1

我有一张桌子,例如:

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

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

目前我正在做类似的事情

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

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

4

2 回答 2

2

试试这个

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
于 2012-10-16T05:46:03.350 回答
1

试试这个:

select t1.months from
(select top 1 t.months as months,max(t.years) as years from
(select years,max(months) as months from cal group by years) t
group by t.months) t1
于 2012-10-16T05:53:08.380 回答