数据结构:
有一张临时表#t,有三列,分别为A,B,C
具体数据如下
A B C
-------------
1 1 1
1 2 0
1 3 1
1 4 0
现想做到把C=0的某行数据,插入该行下面
结果
A B C
-------------
1 1 1
1 2 0
1 2 0
1 3 1
1 4 0
1 4 0
我使用的SQL语句如下:
create table #t
(
A int,
B int,
C int
)
insert into #t
select 1,1,1 union all
select 1,2,0 union all
select 1,3,1 union all
select 1,4,0
select * from #t
union all
select * from #t where C = 0
order by B,C
想求教论坛各位达人,有没有更好的算法
谢谢
SQL 算法
------解决方案--------------------
create table #t
(
A int,
B int,
C int
)
insert into #t
select 1,1,1 union all
select 1,2,0 union all
select 1,3,1 union all
select 1,4,0
go
insert into #t
select * from #t where C =0
go
select * from #t
------解决方案--------------------
create table #t
(
A int,
B int,
C int
)
insert into #t
select 1,1,1 union all
select 1,2,0 union all
select 1,3,1 union all
select 1,4,0
go
insert into #t
select * from #t where C =0
go
select * from #t
ORDER BY b,c
/*
A B C
----------- ----------- -----------
1 1 1