次のようなテーブルがあります。
Year | Month
------------
2011 10
2011 11
2012 5
2012 6
クエリは、最新の「年」に対して最新の「月」を返す必要があります。
現在、私は次のようなことをしています
"年" が表から MAX("月") を選択 (表から MAX("年") を選択)
しかし、私はクエリに満足していません。誰かがよりコンパクトでクリーンな方法を提案できますか?
これを試して
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
これを試して:
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