sql语句update通过另外的表更新本表数据为何不行啊???

xxxuan 2010-05-15 11:28:32
sql语句update通过另外的表更新本表数据为何不行啊???:
update s set s.qty=s.qty+b.qty
from stock s,person b
where s.per_no=b.per_no
and b.per_no='02';
...全文
134 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Adebayor 2010-05-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 xxxuan 的回复:]
sql语句update通过另外的表更新本表数据为何不行啊???:
update s set s.qty=s.qty+b.qty
from stock s,person b
where s.per_no=b.per_no
and b.per_no='02';
[/Quote]
表连接条件没有关联上
fxianxian 2010-05-16
  • 打赏
  • 举报
回复
sql server的写法跟oracle的写法不一样啊
心中的彩虹 2010-05-16
  • 打赏
  • 举报
回复
[Quote=引用楼主 xxxuan 的回复:]
sql语句update通过另外的表更新本表数据为何不行啊???:
update s set s.qty=s.qty+b.qty
from stock s,person b
where s.per_no=b.per_no
and b.per_no='02';
[/Quote]



update stock s set qty=qty+(select qty from person where s.per_no=per_no and per_no='02')

merge into stock s using person b on(s.per_no=b.per_no and b.per_no='02')
when matched then update set s.qty=s.qty+b.qty





duqiangcise 2010-05-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 vber1010 的回复:]
update stock s set s.qty=s.qty+(select qty from person b where s.per_no=b.per_no
and b.per_no='02';)
[/Quote]

+1
linsen_519 2010-05-15
  • 打赏
  • 举报
回复
关联表不能这么改

你可以尝试 在外键里面再加一行新的内容(你想改成什么)
然后把子表里面的内容更新,再把外键的旧信息删除
vber1010 2010-05-15
  • 打赏
  • 举报
回复
update stock s set s.qty=s.qty+(select qty from person b where s.per_no=b.per_no
and b.per_no='02';)

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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