id | unqid
___|________
1 | v1
2 | v1
3 | v1
4 | v1
5 | v4
6 | v4
7 | v9
8 | v9
9 | v9
10 | v2
11 | v7
我需要获得最重复的值,限制为5,就像 V1 V9 V4 V2 V7
我已经尝试过这段代码,但没有显示任何内容
SELECT unqid, COUNT(*) TotalCount FROM votes GROUP BY unqid HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC
答案 0 :(得分:1)
我不确定这是否只是Oracle的事情,如果这不适用于你,请道歉,但我会这样做
select unqid, TotalCount
from (
select unqid, count(*) as TotalCount
from votes
group by unqid
order by TotalCount desc
)
where TotalCount > 1