34,594
社区成员
发帖
与我相关
我的任务
分享
select top 3 姓名,count(1) from tb
group by 姓名 having count(1)>1
order by 2 desc
[Quote=引用 3 楼 xiaoyaodeyun2008 的回复:]select top 3 姓名,count(1) from tb
group by 姓名 having count(1)>1
order by 2 desc
select top 1 姓名,count(1) from tb
group by 姓名 having count(1)>1
order by 2 desc
select * from tb t where age=(select max(age) from tb where name=t.name)
select top 1 name from tb where name in (select 姓名 from tb group by 姓名 having count(1)>1)
1.查出所有的姓名和年龄,姓名重复的只查出年龄最大的那一个
select * from (
select rid=row_number() over (partition by 姓名 order by 年龄 desc),* from tb
) t
where rid=1
2.查出重复次数最多的姓名
select 姓名,count(1) from tb
group by 姓名 having count(1)>1
order by 2 desc