declare @tb table (id int,name varchar(50)) insert into @tb select 1,'a' insert into @tb select 2,'b' insert into @tb select 3,'a' insert into @tb select 4,'c' insert into @tb select 5,'d' insert into @tb select 6,'b' insert into @tb select 7,'c'select * from @tb t where exists( select 1 from @tb where name=t.name group by name having count(1)>1 ) order by name,idid name 1 a 3 a 2 b 6 b 4 c 7 c
select * from 表 order by name,id
如果名字不规则 id name spec val 1 butt 09_1 1 2 yve 23_1 0 3 huy U_2 1 4 butt 09_1 1 5 huy U_2 1 6 ccer Nb_21 1 按照自动name进行分组排序?
insert into @tb select 1,'a'
insert into @tb select 2,'b'
insert into @tb select 3,'a'
insert into @tb select 4,'c'
insert into @tb select 5,'d'
insert into @tb select 6,'b'
insert into @tb select 7,'c'select * from @tb t where exists(
select 1 from @tb where name=t.name
group by name
having count(1)>1
)
order by name,idid name
1 a
3 a
2 b
6 b
4 c
7 c
id name spec val
1 butt 09_1 1
2 yve 23_1 0
3 huy U_2 1
4 butt 09_1 1
5 huy U_2 1
6 ccer Nb_21 1
按照自动name进行分组排序?