MySQL 查询仅选择日期组的最后一行
我有以下查询:
SELECT elo, date(date_calculated) date FROM users_historical_elo WHERE uid =36 order by id asc
产生以下结果:
|埃洛 |日期
|984|2011-04-04
|1010|2011-04-04
|1036|2011-04-04
|1016|2011-04-08
|1000|2011-04-08
|944|2011-04-09
|973|2011-04-09
...
我需要帮助编写一个仅选择的查询最后一个“elo”按日期分组。所以输出应该是:
|埃洛 |日期
|1036|2011-04-04
|1000|2011-04-08
|973|2011-04-09
...
谢谢!
I have the following query:
SELECT elo, date(date_calculated) date FROM users_historical_elo WHERE uid =36 order by id asc
that produces this result:
| elo | date
|984|2011-04-04
|1010|2011-04-04
|1036|2011-04-04
|1016|2011-04-08
|1000|2011-04-08
|944|2011-04-09
|973|2011-04-09
...
I need help writing a query that selects only the last "elo" grouping by date. So the output should be:
| elo | date
|1036|2011-04-04
|1000|2011-04-08
|973|2011-04-09
...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果
id
是表的主键,那么这样做:If
id
is the primary key of the table, then this will do:尝试:
SELECT elo, date(date_calculated) date FROM users_historical_elo WHERE uid =36 group by date order by id asc
Try:
SELECT elo, date(date_calculated) date FROM users_historical_elo WHERE uid =36 group by date order by id asc
我认为你需要使用 MAX 和 GROUP By。请参阅http://www.tutorialspoint.com/mysql/mysql-max-function。 htm
我认为这会起作用
I think you need to use MAX and GROUP By. See http://www.tutorialspoint.com/mysql/mysql-max-function.htm
I think this will work
这:
会返回 elo 和任何 elo 的最后日期,这似乎是您所要求的?
This:
Would return the elo and the last date for any elo, which seems to be what you are asking for?