如题。
比如有一张表table,字段aaa和字段bbb,结构如下:
aaa bbb
13411111111 13522222222
13433333333 13544444444
13455555555 13566666666
13477777777 13588888888现在想把字段b的所有记录追加插入到字段a中,得到结果为:
aaa
13411111111
13433333333
13455555555
13477777777
13522222222
13544444444
13566666666
13588888888请问sql语句怎么写?
比如有一张表table,字段aaa和字段bbb,结构如下:
aaa bbb
13411111111 13522222222
13433333333 13544444444
13455555555 13566666666
13477777777 13588888888现在想把字段b的所有记录追加插入到字段a中,得到结果为:
aaa
13411111111
13433333333
13455555555
13477777777
13522222222
13544444444
13566666666
13588888888请问sql语句怎么写?
select bbb from table;delete from table
where aaa is not null and bbb is null;
drop table #temp
create table #temp
(
aaa varchar(100),
bbb varchar(100))
goinsert into #temp values('13411111111', '13522222222')
insert into #temp values('13433333333', '13544444444')
insert into #temp values('13455555555', '13566666666')
insert into #temp values('13477777777', '13588888888')
goselect * from #tempselect a.aaa as aaa from #temp a
union
select b.bbb from #temp b
select bbb,''
from tb
where bbb not in (select aaa from tb)
select bbb from table
--插入结果到一个临时表
select *
into #temp
from (
select aaa from your_table
union all
select bbb from your_table
) a
values select bbb from tablename