gpt4 book ai didi

mysql - 如何从一组复合行中找到最大值?

转载 作者:行者123 更新时间:2023-11-29 05:33:16 25 4
gpt4 key购买 nike

我有一个表格,例如:

Year | Month
------------
2011 10
2011 11
2012 5
2012 6

查询应返回最新“年”的最新“月”。

目前我正在做类似的事情

Select MAX("Month") from table where "Year" in (select MAX("Year") from table)

但我对查询不满意。有人可以建议一种更紧凑、更清洁的方式吗?

最佳答案

试试这个

select top 1
"Month"
from table
order by "Year" desc, "Month" desc

好吧,对于MySQL我觉得应该是

select
"Month"
from table
order by "Year" desc, "Month" desc
limit 1

关于mysql - 如何从一组复合行中找到最大值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12908254/

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