mssql 中如何查询某一列数据中出现次数最多的的一条
比如我有一个表 dbo.school 里面有列id name sex score
现在想查询score中出现次数做多的一条数据
求高手指点
坐等 mssql 查询
[解决办法]
那你这怎么会是获取一条呢,应该是多条才对吧?
select * from tb where score in(
select top 1 score from tb group by score order by count(1) desc
)
[解决办法]
declare @school table(id int, name varchar(20), sex varchar(10), score int)
insert into @school
select 1,'张三','男',85 union all
select 2,'李四','男',95 union all
select 3,'王五','男',75 union all
select 4,'李六','男',70 union all
select 5,'王二','男',85
select top 1 score
from @school
order by (COUNT(*) over(PARTITION by score)) desc
/*
score
85
*/