| 关键词: nbsp 张三 王五 李四 select 字段 TableA 777777 555555 customer |
例:表中有条六条记录。 其中张三和王五 的记录有重复 TableA id customer PhoneNo 001 张三 777777 002 李四 444444 003 王五 555555 004 张三 777777 005 张三 777777 006 王五 555555 如何写一个sql语句将TableA变成如下 001 张三 777777 002 李四 444444 003 王五 555555 --测试环境 create table TableA ( id varchar(3),customer varchar(5),PhoneNo varchar(6)) insert into TableA select '001','张三','777777' union all select '002','李四','444444' union all select '003','王五','555555' union all select '004','张三','777777' union all select '005','张三','777777' union all select '006','王五','555555' --结果 delete TableA from TableA T where exists( select 1 from tablea where customer=T.customer and phoneno=T.phoneno and id < tt.id ) --总结 该方法适用于有一个字段为自增性,例如本例中的:id delete 表名 from 表名 as T where exists( select 1 from 表名 where 字段A=T.字段A and 字段B=T.字段B,(…) and 自增列 < T.自增列 ) |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|