选择每组最后 30 个项目
希望标题有意义。
对于这个例子,我将在我的数据库中有下一个表
measurements
==================================
stn | date | temp | time =
1 | 01-12-2001 | 2.0 | 14:30 =
1 | 01-12-2001 | 2.1 | 14:31 =
1 | 03-12-2001 | 1.9 | 21:34 =
2 | 01-12-2001 | 4.5 | 12:48 =
2 | 01-12-2001 | 4.7 | 12:49 =
2 | 03-12-2001 | 4.9 | 11:01 =
==================================
等等。
每个站 (stn) 有许多测量值,每<罢工>天秒一次。现在我想选择过去 30 天 测量中每个站点的温度,其中该站点至少有 30 个温度测量值。
我正在使用子查询和分组依据,但我似乎无法弄清楚。
希望有人能在这里帮助我。
编辑表格 我的例子过于简单化,遗漏了一条关键信息。请检查问题。
Hopefully the title makes any sense.
For this example I'll have the next table in my database
measurements
==================================
stn | date | temp | time =
1 | 01-12-2001 | 2.0 | 14:30 =
1 | 01-12-2001 | 2.1 | 14:31 =
1 | 03-12-2001 | 1.9 | 21:34 =
2 | 01-12-2001 | 4.5 | 12:48 =
2 | 01-12-2001 | 4.7 | 12:49 =
2 | 03-12-2001 | 4.9 | 11:01 =
==================================
And so on and so forth.
Each station (stn) has many measurements, one per day second. Now I want to select the temp of each station of the last 30 days measurements where the station has at least 30 temperature measurements.
I was playing with subquerys and group by, but I can't seem to figure it out.
Hope someone can help me out here.
edited the table
My example was oversimplified leaving a critical piece of information out. Please review the question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此查询应选择
最后 30 个条目,其中一个电台至少有 30 个条目
此查询基于
nick Rulez
此处的答案,因此请为他投票我已经在根据您的架构制作的示例数据库上对其进行了测试,并且工作正常。
要了解有关此类查询的更多信息,请查看此处组内配额(每组前 N 个)< /a>
This is the query that should select
Last 30 entries where there are at least 30 entries for a station
This query is based on the answer here by
nick rulez
, so please upvote himI have tested it on a sample database I made based on your schema and is working fine.
To know more about such queries have a look here Within-group quotas (Top N per group)
这是我正在寻找的问题吗?很抱歉,如果我的问题“非常错误”,以至于把你们都推向了错误的方向。我将对帮助我找到所需查询的答案进行投票。
Is the query I was looking for, sorry if my question was 'so wrong' that it pushed you all in the wrong direction. I'll up vote the answers who'm helped me to find the needed query.