根据一张表的一个属性(比如年龄)大于20作为条件判断,要求将所有年龄大于20的id字插入到另外纸张表中
select id from member where age>20这是子查询,并且结果不止返回一个,
但外围父查询要进行表的插入,要取得子查询中所有符合条件的人的id,
简单一句话,想遍历子查询中所有项给父查询传值
Thank you!!
select id from member where age>20这是子查询,并且结果不止返回一个,
但外围父查询要进行表的插入,要取得子查询中所有符合条件的人的id,
简单一句话,想遍历子查询中所有项给父查询传值
Thank you!!
是否是这个?
insert into linu select 1,0
insert into linu select 2,1
insert into linu select 3,1
insert into linu select 5,3
insert into linu select 6,2insert into linu select * from linu
go
drop table linu
drop table tb
go
create table tb
(
id int,
age int
)
insert into tb(id,age)values(1,33)
insert into tb(id,age)values(2,19)
insert into tb(id,age)values(3,20)
insert into tb(id,age)values(4,1)
insert into tb(id,age)values(5,30)
insert into tb(id,age)values(6,11)drop table tb2
go
create table tb2
(
id int,
age int
)insert into tb2 select * from tb where id in( select id from tb where age>20)
select * from tb2
/*
id age
1 33
5 30
*/