select x.*
from (select val,
count(*) as cnt,
row_number() over (order by count(*) desc ) as seqnum,
count(*) over () as num_vals
count(*) over (partition by count(*)) as cnt_cnt
from table
group by val
) x
where cnt_cnt = 1 and seqnum = 1 and num_vals > 1;
實際上,您可以使用having子句和order by來實作:
select val
from (select val, count(*) as cnt,
count(*) over () as num_values
from table
group by val
) v
where num_values > 1
order by cnt desc;
您可以計算值的數量,找出頻率最高的值,也可以根據值的數量進行篩選:
實際上,您可以使用
having
子句和order by
來實作: