数据库问题,帮提有分(200分)

  • 主题发起人 luosheng
  • 开始时间
L

luosheng

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么实现从一个表的指定字段的数据插入另外一个表的指定字段中(两个字段名不同)
同时进行运算;
例:
表1:l1 l2 l3 l4 ……
表2:k1 k2 k3 k4……
现在我要求把l1 l2 的值给k1 k2 同时l3给k3 l3+l4给k4

 
insert into 表1 (l1,l2,l3... )
select k1,k2,k3,...from 表2
 
insert 表2( k1,k2,k3,k4)
select l1 k1,l2 k2,l3 k3,l3+l4 k4
from 表1
 
insert into 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
 
我和 Qucicksilver是一样的解答,
也是 insert into 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
我亲自试过的,肯定是正确的!

但是有一条,表1和表2相对应的字段的定义要一致!!
 
insert into urights(username,rights) select rymc,qx from ry
 
同意QuickSilver :for Oracle
 
是什么数据库啊,有些数据库还可以这么写
insert 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
没有 into 的事, 就是 完颜康 的写法 [:D]
 
QuickSilver,的可以
 
insert into 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
 
insert 表2( k1,k2,k3,k4)
select l1 k1,l2 k2,l3 k3,l3||l4 k4
from 表1;

INFORMIX
 
我用这样怎么不行
insert into 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4,表1.id,表2.id from 表1,标2
where 表1.id=表2.id
要怎么做??
 
insert into 表2 (k1,k2,k3,k4)
select l1,l2,l3,l3+l4 from 表1,表2 where 表1.id=表2.id

 
如果不是id呢,是其他字段怎么办?
 
insert 表2 ( k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
 
如果我是另外一个不要插入的字段进行比较又要怎么做?
比如说有BH字段(都有),但是不要插入。要怎么写
 
我和 Qucicksilver是一样的解答,
也是 insert into 表2 (k1,k2,k3,k4) select l1,l2,l3,l3+l4 from 表1
我亲自试过的,肯定是正确的!

但是有一条,表1和表2相对应的字段的定义要一致!! 我在SQL SERVER 2000下运行通过了啦
!!

 

Similar threads

顶部