查询出重复数据中第一列除外的数据,保留重复数据第一条
表 Table :ID,Name,Phone
一,查询出所有Name重复的数据按Name排序
select * from Table where Name in (select Name from T group by Name having count(Name) > 1) order by Name
二,查重排序后,重复的数据保留第一条
with tab as (select ROW_NUMBER() OVER (ORDER BY NAME ASC)AS num,*
from Table where NAME in (select Name from Table where Name !='' group by Name having count(Name) > 1) )
select * from tab where tab.num not in (select min(tab.num) from tab group by Name)order by tab.num