如何删除表中的重复记录??50分求 delete a from 表 a where exists(select 1 from 表 where col1=a.col1 and col2=a.col2 and sn<a.sn) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 delete 表 where sn not in(select min(sn) from 表 group by col1,col2) select distinct col1,col2 into # from 表truncate table 表insert into 表 select * from #drop table # 可以換種思維呀﹐用 select DISTINCT * into newtable from tb_name 把沒有重量的記錄放到另一個表中 select distinct * into #tmp from tb_name drop table tb_nameselect * into tb_name from #tmpdrop table #tmp DELETE L FROM tb_name L JOIN tb_name RON L.col1 = R.col1 AND L.col2 = R.col2 AND L.sn > R.sn --建立测试环境declare @table1 table(sn int,col1 int,col2 int)insert @table1 select 1,1,1 unionselect 2,1,1 unionselect 3,2,2 unionselect 4,2,2 unionselect 5,3,3 unionselect 6,3,3--执行delete from @table1 where sn in (select max(sn) from @table1 group by col1,col2 )--查看结果select * from @table1(所影响的行数为 6 行)(所影响的行数为 3 行)sn col1 col2 ----------- ----------- ----------- 1 1 13 2 25 3 3(所影响的行数为 3 行) 为什么要在 default 后面加上 's%' getdate()呢 数据库中已存在名为 'worker' 的对象。 SQL server 存储过程中执行出错时回滚 如何能缩短sql语句的执行时间 文本定长字段插入语句? 关于分组的语句如何写 我知道这个问题能用游标解决,可是我不知道怎么写 exist与in的奇怪问题! 我是初学者,关于pb 和 sql server 的 ,一定给分呀!!!分可以再加呀 限制返回的记录数 向各位老大求救一个关于返回总纪录数的有条件的存储过程 请问MSSQL中的日期函数是什么?
truncate table 表
insert into 表 select * from #
drop table #
drop table tb_name
select * into tb_name from #tmp
drop table #tmp
FROM tb_name L
JOIN tb_name R
ON L.col1 = R.col1 AND L.col2 = R.col2 AND L.sn > R.sn
declare @table1 table(sn int,col1 int,col2 int)
insert @table1
select 1,1,1 union
select 2,1,1 union
select 3,2,2 union
select 4,2,2 union
select 5,3,3 union
select 6,3,3
--执行
delete from @table1 where sn in (select max(sn) from @table1 group by col1,col2 )
--查看结果
select * from @table1(所影响的行数为 6 行)
(所影响的行数为 3 行)sn col1 col2
----------- ----------- -----------
1 1 1
3 2 2
5 3 3(所影响的行数为 3 行)