gpt4 book ai didi

MySQL 的一列与另一最大列不同

转载 作者:行者123 更新时间:2023-11-29 09:03:39 25 4
gpt4 key购买 nike

假设我有这个查询:

SELECT report_id, time_sent
FROM report_submissions
WHERE report_id IN (1,2,3,4,5,6)
ORDER BY report_id ASC, time_sent DESC

结果如下:

report_id   time_sent
1 2
1 1
2 4
2 3
3 4

我想更改该查询,以便获得一个不同的 report_id 及其 max(time_sent),例如:

report_id   time_sent
1 2
2 4
3 4

如何以最有效的方式做到这一点?谢谢。

最佳答案

SELECT report_id, max(time_sent)
FROM report_submissions
WHERE report_id IN (1,2,3,4,5,6)
GROUP BY report_id
ORDER BY report_id ASC

关于MySQL 的一列与另一最大列不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7757513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com