请教一个数据记录插入问题
如何往一个表中插入一条记录,其中部分字段值是自行指定的,部分字段值来自于另一个表,可以用一条sql语句实现吗?
比如待插入表里面有两个字段:
create table t(
field1 int,
filed2 int)
插入的时候,其中field1可以自己指定值,filed2来自于另外一个表的某个字段。
比如待插入表里面有两个字段:
create table t(
field1 int,
filed2 int)
插入的时候,其中field1可以自己指定值,filed2来自于另外一个表的某个字段。
作者: dyzhen 发布时间: 2011-05-12
SQL code
insert into t3(field1,filed2) Select 1,(select filed2 from t2 where id=1) From t2 group by 1
作者: lxq19851204 发布时间: 2011-05-12
insert into t(filed1,filed2)
seelct 1,col1 from tb
seelct 1,col1 from tb
作者: rucypli 发布时间: 2011-05-12
引用 1 楼 lxq19851204 的回复:
SQL code
insert into t3(field1,filed2)
Select 1,(select filed2 from t2 where id=1) From t2 group by 1
SQL code
insert into t3(field1,filed2)
Select 1,(select filed2 from t2 where id=1) From t2 group by 1
可行,,原来group by还可以这样用!谢谢。。
作者: dyzhen 发布时间: 2011-05-12
引用 2 楼 rucypli 的回复:
insert into t(filed1,filed2)
seelct 1,col1 from tb
insert into t(filed1,filed2)
seelct 1,col1 from tb
这个方法也可以
作者: dyzhen 发布时间: 2011-05-12
引用 1 楼 lxq19851204 的回复:
SQL code
insert into t3(field1,filed2)
Select 1,(select filed2 from t2 where id=1) From t2 group by 1
SQL code
insert into t3(field1,filed2)
Select 1,(select filed2 from t2 where id=1) From t2 group by 1
lxq19851204,弱弱问一下,group by 1本质含义是什么,1代表什么意思,我只知道它可以跟字段,但每见过这种用法。。
作者: dyzhen 发布时间: 2011-05-12