1,select * from table where 学号 not in (select max(学号) from table group by 姓名)
2,Delete table where 学号 not in (select max(学号) from table group by 姓名)
2,Delete table where 学号 not in (select max(学号) from table group by 姓名)
解决方案 »
- 紧急求助,两台机器的MSSQL连接问题
- 两个表通过外键连接,在查询时可否直接获取所有字段内容而不必通过在查询语句中写
- 为什么powerDesigner 11 没有关联 Relationship工具
- 把A表中的一条数据插入B表.该怎么写.
- 请教:用a表‘left join’ b表返回记录数多于a表
- 渴求帮助!存储过程批复制!急
- 2个表的查询问题,也许不难!
- 请教一个SQL语句
- 这里没有人关心Yokun吗?还是大家都在闭门造车?
- 怎样删除内容中含有 的数据阿?
- 在出入库表中分别有物资编号(MaterialCode),仓库代号(StorageID)和出入库数量(Number),出库时间(OutStockDate),入库时间(InStockDate),现
- 加了encryption的存储过程?
2 select * from table1 where 学号 in(select max(学号),姓名 from table1 group by 姓名)
2 delete from table1 where 学号 not in(select max(学号),姓名 from table1 group by 姓名)
2 sensory
3 test
3 test
4 cow
4 cow
4 cow的情况 写错了 我去年的面试题
2删除需要借助临时表了。我没有想到不用临时表的方法。
2删除需要借助临时表了。我没有想到不用临时表的方法。
into newtable
from yourtable
group by 学号,姓名
drop table yourtable
exec sp_rename newtable,yourtable
上面一位大侠的代码很好,也可以这样:
select 学号,姓名
into #newtable --在表名前加‘#’,并将不重复的记录加入其中
from yourtable
group by 学号,姓名
go
truncate table yourtable
go
insert yourtable
select *
from #newtable
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,如果是判断所有字段也可以这样
select * into #aa from table group by id1,id2,....
delete table
insert into table
select * from #aa3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
delect # where id not in (
select max(id) from # group by col1,col2,col3...)
delect table
inset into table(...)
select ..... from #temp
col1+','+col2+','...col5 联合主键
select * from table where col1+','+col2+','...col5 in ( select max(col1+','+col2+','...col5) from table
where having count(*)>1
group by col1,col2,col3,col4
)
group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
select identity(int,1,1) as id,* into #temp from tabel
select * from #temp where id in (
select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)