oracle 同时取最大最小值,如图

要求 ,一条语句,非union
2024年11月15日 11:25
有2个网友回答
网友(1):

select max(case when d.cnt = d.max_cnt then d.crown else null end) as max_crown,d.max_cnt, max(case when d.cnt = d.min_cnt then d.crown else null end) as min_crown, d.min_cnt
from (
select s.crown, s.cnt, max(s.cnt) over () as max_cnt, min(s.cnt) over () as min_cnt
from (
select s0.crown, count(s0.year) as cnt
from history s0
group by s0.crown
) s
) d
group by d.max_cnt, d.min_cnt;
结果中, max_crown为夺冠最多的球队名称, max_cnt为球队最多的夺冠次数; min__crown为夺冠最少的球队名称, min_cnt为球队最少夺冠次数.

网友(2):

select max(count(crown)),min(count(crown) from history 试试 没这么写过