求写一条SQL语句

2025-02-26 21:20:54
推荐回答(6个)
回答1:

select top 2 * from
(select num,count(0) as countnum from test group by num) tt
order by countnum desc

回答2:

select top 2 num, count(*) as countn from test group by num order by count(*) desc

回答3:

select top 2 num,count(num) as fcount from test group by num order by fcount desc

回答4:

二楼apu510064 的回答是正确的!

回答5:

MYSQL版本:
SELECT COUNT(num) AS n, id
FROM test
GROUP BY num
ORDER BY n DESC
limit 2

回答6:

select top 2 num 值,count(num) 次数 from test group by num ORDER BY num