DELETE数据的查询
表结构:
ID COL
1 2434
2 454
3 342
4 67
5 [NULL]
6 [NULL]
7 23432
8 32
9 [NULL]
10 23
11 [NULL]
12 1232
13 [NULL]
14 [NULL]
15 [NULL]
要求删除完了得到这个结果:
ID COL
4 67
5 [NULL]
6 [NULL]
8 32
9 [NULL]
10 23
11 [NULL]
12 1232
13 [NULL]
14 [NULL]
15 [NULL]
也就是说空字段以及最前面的那个非空字段保留,其他删除
靠!我又用游标了…………是这么写的:
declare CUR_ID cursor for
select ID,COL from TABLE1 order by ID
open CUR_ID
fetch next from CUR_ID into @ID,@COL
while @@FETCH_STATUS = 0
begin
fetch next from CUR_ID into @ID,@COL
if @COL is not null
begin
if exists(select 1 from TABLE1 where ID = @ID -1 and COL is not null)
delete from TABLE1 where ID = @ID -1
end
end
close CUR_ID
deallocate CUR_ID
这个效率实在不咋地……有没有好办法?