id | language
---------
01 | Java
---------
01 | Python
---------
01 | C#
---------
02 | Java
例如,01具有最高的频率,因为他学习最多的语言,那么我如何获得频率最高的id?
答案 0 :(得分:0)
您可以加入CTE:
with x as (
select id, count(*) as c from my_table group by id
),
m as (select max(c) as t from x)
select x.id
from x
join m on x.c = m.t
答案 1 :(得分:0)
select top 1 id, count(id) frequency
from #mytable
group by id
order by frequency desc