如何将table2的数据update到table1中?

cqiu2000 2002-06-24 01:19:57
table1与table2结构相同 ,table1与table2的根据字段sid相关连
table2为临时记录表 ,
如何将talbe2的记录数据按照sid关连分别加到talbe1对应的数据

表结构如下
sid number(10) ;
value number(20,2);
...全文
65 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
deepbluesea 2002-06-27
  • 打赏
  • 举报
回复
delete from table1 where sid in (select sid from table2);

insert into table1 select * from table2;

(最好用事务,仅供参考)
hammer_shi 2002-06-24
  • 打赏
  • 举报
回复
update table1 table1 set table1.value=table1.value+(select table1.value from table2 table2 where tabel1.sid=table2.sid);
hammer_shi 2002-06-24
  • 打赏
  • 举报
回复
update table1 table1 set table1.value=table1.value+(select value from table2 table2 where tabel1.sid=table2.sid);
cqiu2000 2002-06-24
  • 打赏
  • 举报
回复
update table1 set value=value+(select value from table2 where table1.sid=table2.sid);
搞定了,多谢,马上给分
blue__star 2002-06-24
  • 打赏
  • 举报
回复
update table1 table1 set value=(select value from table2 table2 where tabel1.sid=table2.sid);
是可以的
SID 是唯一的
hammer_shi 2002-06-24
  • 打赏
  • 举报
回复
哦,你的sid肯定为唯一,要是不唯一你怎么知道要取那个值作为更正的?呵呵,我的方法可以得哟!
cqiu2000 2002-06-24
  • 打赏
  • 举报
回复
我的意思是:将table2的value+对应的table1的value保存于table1 ,
不是 table2的value将talble1的value覆盖
walterzh 2002-06-24
  • 打赏
  • 举报
回复
不行吧,如果VALUE值不唯一呢?
hammer_shi 2002-06-24
  • 打赏
  • 举报
回复
update table1 table1 set value=(select value from table2 table2 where tabel1.sid=table2.sid);
walterzh 2002-06-24
  • 打赏
  • 举报
回复
建个procedure
cursor a is select * from table1 for update of ...
cursor b(a number) is select * from table2 where sid=a;
update table1 ....where current of ...

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧