我有表billa有列:currency,amount和billed_at。
我想从每种货币的最大billed_at获取最低billed_at
使用此查询可以获取每种货币的最大billed_at
SELECT MAX(billed_at), currency FROM bills GROUP BY currency
例如,它返回了2行
2013-12-16 13:31:18 UTC,“EUR”
2013-12-02 14:57:00 UTC,“USD”
然后我需要从此结果中获取最小billed_at。我怎么能这样做?
提前致谢!
答案 0 :(得分:2)
您应该将您的查询作为子句使用from子句作为打击
select min(billed_at)
from (SELECT MAX(billed_at), currency FROM bills GROUP BY currency) AS Tab
答案 1 :(得分:0)
SELECT MIN(billed_at_max)
FROM (SELECT MAX(billed_at)billed_at_max FROM bills GROUP BY currency)x