如何在SQL列中找到最大的区别?(How to find the biggest difference in an SQL column?)
我有一张包含以下信息的表格:
表:酒吧
minute | beer 1 | 48 2 | 24 3 | 92 4 | 17 5 | 38 6 | 64我想知道柱啤酒的最大区别是什么或哪里。 通过亲眼看到它,它在3分钟到4分之间,但我怎么能在SQL中做到这一点?
我有一些想法:
Select minute, count(beer) as spike from bar where ???I have a table with the following information:
Table: bar
minute | beer 1 | 48 2 | 24 3 | 92 4 | 17 5 | 38 6 | 64I want to know what or where the biggest difference is in the column beer. By manually seeing it with my own eyes, it's between minute 3 and 4, but how can I do this in SQL?
I had something in mind:
Select minute, count(beer) as spike from bar where ???最满意答案
您需要嵌套聚合:
select max(spike) - min(spike) from ( -- count per minute Select minute, count(beer) as spike from bar group by minute ) as dtYou need nested aggregation:
select max(spike) - min(spike) from ( -- count per minute Select minute, count(beer) as spike from bar group by minute ) as dt更多推荐
发布评论