mysql查询帮助 - 获取最大(日期)
我有如下所示的表:
类型 | 值_1 | value_2 | standby_date |
---|---|---|---|
a | 50 | 20 | 2022-06-01 |
A | 100 | 40 | 2022-06-06 |
A | 200 | 60 | 2022-06-06-04 |
B | 300 | 80 | 2022-06-06-06--06- |
B | 400 | 100 100 100 | 2022-06-06-06-03 09 |
我试图以最新的待机日期获得值_1和value_2的总和,其中一个查询中的type = a。因此,结果将如下所示:
类型 | sum(value_1) | sum(value_2) | standby_date |
---|---|---|---|
a | 350 | 120 | 2022-06-06 |
希望知道要达到上述结果的查询是什么。谢谢您!
I have table as shown below:
Type | Value_1 | Value_2 | Standby_Date |
---|---|---|---|
A | 50 | 20 | 2022-06-01 |
A | 100 | 40 | 2022-06-06 |
A | 200 | 60 | 2022-06-03 |
B | 300 | 80 | 2022-06-04 |
B | 400 | 100 | 2022-06-09 |
I am trying to get sum of value_1 and value_2 with the latest standby date where type = A in one query. Thus, the result will be as shown below:
Type | SUM(Value_1) | SUM(Value_2) | Standby_Date |
---|---|---|---|
A | 350 | 120 | 2022-06-06 |
Would like to know what is the query to achieved the above result. Thank you in advanced!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要使用
max
来获取组中的最大日期,sum
获得总计:You just need to use
max
to get the greatest date in a group, andsum
to get the totals: