主题:救急,谢谢关于一个语句
truement
[专家分:270] 发布于 2006-07-16 22:16:00
delete from CombInfo where (NO4=NO3+1 and NO3=NO2+1 and NO2=NO1+1) or (NO5=NO4+1 and NO4=NO3+1 and NO3=NO2+1)
上面的sql语句问什么不能正确执行?语句中的NO几,都代表数字,想实现的功能是如果整数NO1 NO2 NO3 NO4 NO5有4个或全部连续则删除,如前4个连续1 2 3 4 7 ,全部连续 4 5 6 7 8 9 ,后4个连续2 5 6 7 8 ,另外,数字是以整型存储的.
回复列表 (共2个回复)
沙发
a97191 [专家分:4040] 发布于 2006-07-17 09:42:00
经测试没有问题
declare @t table(no1 int,no2 int,no3 int,no4 int,no5 int)
insert @t select 1,2,3,4,7
union all select 4,5,6,7,8declare @t table(no1 int,no2 int,no3 int,no4 int,no5 int)
insert @t select 1,2,3,4,7
union all select 4,5,6,7,8
union all select 2,5,6,7,8
delete from @t where (no4=no3+1 and no3=no2+1 and no2=no1+1) or (no5=no4+1 and no4=no3+1 and no3=no2+1)
union all select 2,5,6,7,8
delete from @t where (no4=no3+1 and no3=no2+1 and no2=no1+1) or (no5=no4+1 and no4=no3+1 and no3=no2+1)
板凳
truement [专家分:270] 发布于 2006-07-17 12:25:00
谢谢.另外我是用VC操作的access,可能是我别的地方出了问题.
我来回复