假设我有下表
claim_date person_type
------------------------
01-01-2012 adult
05-05-2012 adult
12-12-2012 adult
12-12-2012 adult
05-05-2012 child
05-05-2012 child
12-12-2012 child
当我执行以下查询时:
select
claim_date,
sum(case when person_type = 'adult' then 1 else 0 end) as "nbr_of_adults",
sum(case when person_type = 'child' then 1 else 0 end) as "nbr_of_children"
from my_table
group by claim_date
;
我在这里得到这个结果:
claim_date nbr_of_adults nbr_of_children
---------------------------------------------
01-01-2012 1 0
05-05-2012 1 2
12-12-2012 2 1
我想收到的是最大成人人数(这里:2)和最大儿童人数(这里:2)。有没有办法通过单个查询来实现这一点?感谢您的任何提示。