mysql查询帮助 - 获取最大(日期)

发布于 2025-02-12 23:00:29 字数 872 浏览 0 评论 0原文

我有如下所示的表:

类型值_1value_2standby_date
a50202022-06-01
A100402022-06-06
A200602022-06-06-04
B300802022-06-06-06--06-
B400100 100 1002022-06-06-06-03 09

我试图以最新的待机日期获得值_1和value_2的总和,其中一个查询中的type = a。因此,结果将如下所示:

类型sum(value_1)sum(value_2)standby_date
a3501202022-06-06

希望知道要达到上述结果的查询是什么。谢谢您!

I have table as shown below:

TypeValue_1Value_2Standby_Date
A50202022-06-01
A100402022-06-06
A200602022-06-03
B300802022-06-04
B4001002022-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:

TypeSUM(Value_1)SUM(Value_2)Standby_Date
A3501202022-06-06

Would like to know what is the query to achieved the above result. Thank you in advanced!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-02-19 23:00:29

您只需要使用max来获取组中的最大日期,sum获得总计:

select type, sum(value_1), sum(value_2), max(standby_date)
from t
where type = 'a'
group by type

You just need to use max to get the greatest date in a group, and sum to get the totals:

select type, sum(value_1), sum(value_2), max(standby_date)
from t
where type = 'a'
group by type
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文