这样的sql语句如何写? Delete A from Table1 A Where Exists(Select * from Table1 Where field1=A.field1 And field2=A.field2 And field3<A.field1) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Delete A from Table1 A Where Exists(Select * from Table1 Where field1=A.field1 And field2=A.field2 And field3<A.field3) --建立测试环境Create table Table1(field1 Int, field2 Int, field3 Int)--插入数据Insert Table1 Values(1, 1, 2)Insert Table1 Values(1, 1, 3)Insert Table1 Values(2, 2, 4)Insert Table1 Values(2, 2, 5)Insert Table1 Values(3, 3, 6)GO--测试Select * from Table1Delete A from Table1 A Where Exists(Select * from Table1 Where field1=A.field1 And field2=A.field2 And field3<A.field3)Select * from Table1--删除测试环境Drop table Table1--结果/*field1 field2 field31 1 21 1 32 2 42 2 53 3 6field1 field2 field31 1 22 2 43 3 6*/ 谢谢paoluo(一天到晚游泳的鱼) 可是我现在遇到如下情况时,还是不能建立主键:field1 field2 field34 4 (空格)4 4 Null这种情况该如何删除呢? 我找到一个办法,就是把是空格的删掉,null的保留delete from table1 where field3='' Create table table1 (field1 Int, field2 Int, field3 varchar(10))--插入数据Insert table1 Values(1, 1, 2)Insert table1 Values(1, 1, 3)Insert table1 Values(2, 2, 4)Insert table1 Values(2, 2, 5)Insert table1 Values(3, 3, 6)Insert table1 Values(4, 4, ' ' )Insert table1 Values(4, 4, null)GOdelete Afrom table111 A,table111 Bwhere A.field1=B.field1 and A.field2=B.field2 and isnull(A.field3,1)<isnull(B.field3,1) Delete A from Table1 A Where Exists(Select * from Table1 Where field1=A.field1 And field2=A.field2 And field3<>A.field1)修改一下 急求一段sql,请大神们帮忙…… 怎么建约束(SQL2000) 请问各位这个语句错误在哪里? 怎么得到小数的整数部分,去尾而不四舍五入 一个文件夹下面有多个dbf文件,怎样一次导入到新建的SQL Server中啊? 一个关于从EXECL内容导入SQL中然后,为其表设置主键的问题?请指教!!! 如何统计总的记录数 !!请问如何利用ADO做三层设计?! 在Windows2000中不装SQL SERVER客户端,通过ODBC连接服务器数据库的问题 sql 查询 本地 - 服务器,不同数据库间数据更新 怎么样建这个用户???提示下!
Create table Table1
(field1 Int,
field2 Int,
field3 Int)
--插入数据
Insert Table1 Values(1, 1, 2)
Insert Table1 Values(1, 1, 3)
Insert Table1 Values(2, 2, 4)
Insert Table1 Values(2, 2, 5)
Insert Table1 Values(3, 3, 6)
GO
--测试
Select * from Table1
Delete A from Table1 A Where Exists(Select * from Table1 Where field1=A.field1 And field2=A.field2 And field3<A.field3)
Select * from Table1
--删除测试环境
Drop table Table1
--结果
/*
field1 field2 field3
1 1 2
1 1 3
2 2 4
2 2 5
3 3 6field1 field2 field3
1 1 2
2 2 4
3 3 6
*/
可是我现在遇到如下情况时,还是不能建立主键:field1 field2 field3
4 4 (空格)
4 4 Null这种情况该如何删除呢?
delete from table1 where field3=''
(field1 Int,
field2 Int,
field3 varchar(10))
--插入数据
Insert table1 Values(1, 1, 2)
Insert table1 Values(1, 1, 3)
Insert table1 Values(2, 2, 4)
Insert table1 Values(2, 2, 5)
Insert table1 Values(3, 3, 6)
Insert table1 Values(4, 4, ' ' )
Insert table1 Values(4, 4, null)
GOdelete A
from table111 A,table111 B
where A.field1=B.field1 and A.field2=B.field2 and isnull(A.field3,1)<isnull(B.field3,1)
修改一下