例如,
AAA
BBB
BBB
CCC
BBB
CCC
DDD
DDD
有4个唯一值(AAA, BBB, CCC, DDD)
,2个重复值两次
(CCC, DDD)
,1次重复三次(BBB)
。我想为这个问题写一个SQL查询。请帮忙
所以答案是4,2,1。
答案 0 :(得分:1)
您可以使用row_number()
:
select, seqnum, count(*)
from (select col, row_number() over (partition by col) as seqnum
from t
group by col
) h
group by seqnum
order by seqnum;