我具的例可能不好理解。我现在就写了一条SQL,在程序中肯定要复杂些,这里就写个大概意思!
insert into a(a1,a2) values ('33',(select b2 from b where b1='1'))
系统说 select b2 where b1='1' 有错
a表
a1 a2
b表
b1 b2
1 100
2 200
3 300
我想要的结果是 向a表添这条记录。33 100
添加后a表
a1 a2
33 100
insert into a(a1,a2) values ('33',(select b2 from b where b1='1'))
系统说 select b2 where b1='1' 有错
a表
a1 a2
b表
b1 b2
1 100
2 200
3 300
我想要的结果是 向a表添这条记录。33 100
添加后a表
a1 a2
33 100
insert a(a1,a2) select '33',b2 from b where b1='1'
如果向a1插入的不是"33"
而是另一个表c 的c2字段 ,c1值为'11'
我象这样写,系统说有错!
insert a(a1,a2) select c2 from c where c1='11' select b2 from b where b1='1'
可以这样:
insert a(a1,a2) select c2,b2 from c,b where c1='11' and b1='1'
当然如果c和b之间没有关系的话,a的记录条数是满足条件的c和b的记录数乘积