|
发表于 2020-6-15 10:00:01
|
显示全部楼层
呵呵,是不是我理解错楼主的意思了?这个问题不难啊。
create table #table
(
[学号] varchar(5),
[姓名] varchar(20),
[性别] varchar(2),
[年龄] int
)
--drop table #table
insert into #table ([学号],[姓名],[性别],[年龄])
select '0001','xw','男',18 union all
select '0002','mc','女',18 union all
select '0003','mc','女',18 union all
select '0004','mc','女',18 union all
select '0005','ww','男',21 union all
select '0006','xw','男',18 union all
select '0007','xw','男',18
--显示需要保留的
select min(学号),[姓名],[性别],[年龄] from #table
group by [姓名],[性别],[年龄] order by min(学号)
--删除不需要保留的
delete --select *
from #table
where [学号] not in (select min(学号) from #table
group by [姓名],[性别],[年龄]) |
|