如何在sql server 数据库中查出重复最多的字段

来源:百度知道 编辑:UC知道 时间:2024/05/02 13:41:22

select top 1 作者ID from 书目表 group by 作者ID order by count(作者ID) desc

--以下是测试数据
declare @book table(author int,book int)
insert @book select 1,1
union all select 2,2
union all select 2,3
union all select 1,4
union all select 2,5
union all select 3,6
union all select 2,7
union all select 3,8
union all select 3,9
select top 1 author from @book group by author order by count(author) desc
--结果
2

重新建立一个表,表字段为作者,出书数量,
重新查询书最多即可