請教一段SQL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!

tohen 2003-10-20 10:02:59
表1:
cs total_jx total_dz
釘珠組 NULL NULL
湘雅 NULL NULL
豐澤 NULL NULL
年輕貴族 NULL NULL
創興 NULL NULL
機繡組 NULL NULL
榮達 NULL NULL

表2:
cs total_jx
年輕貴族 92.43
創興 327.40
榮達 617.21
機繡組 113.76

表3:
cs total_dz
釘珠組 623.51
創興 697.76
湘雅 45.68
榮達 1851.92
豐澤 60.00

要分別把表2,表3中cs字段與表1相同的紀錄的total_jx,total_dz值
update到表1中.
最後得到的結果為:
表1:
cs total_jx total_dz
釘珠組 NULL 623.51
湘雅 NULL 45.68
豐澤 NULL 60.00
年輕貴族 92.43 NULL
創興 327.40 697.76
機繡組 113.76 NULL
榮達 617.21 1851.92
...全文
38 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shuiniu 2003-10-20
  • 打赏
  • 举报
回复
update table1
set total_jx = b.total_jx,
total_dz = c.total_dz
from table1 left join table2 b on
table1.cs = b.cs left join table3 c on
table1.cs = c.cs
wzh1215 2003-10-20
  • 打赏
  • 举报
回复
update 表1 set a.total_jx=b.total_jx from 表1 a,表2 b where a.cs=b.cs
update 表1 set a.total_dz=c.total_dz from 表1 a,表3 c where a.cs=c.cs
yujohny 2003-10-20
  • 打赏
  • 举报
回复
update A
set A.total_jx=B.total_jx,
A.total_dz=C.total_dz
from 表1 A left join 表2 B on B.cs=A.cs
left join 表3 C on C.cs=A.cs
伍子V5 2003-10-20
  • 打赏
  • 举报
回复
update 表1 set total_jx=b.total_jx,total_dz=c.total_dz from 表1 a left join 表2 b on a.cs=b.cs left join 表3 c on a.cs=c.cs
lijinqiang 2003-10-20
  • 打赏
  • 举报
回复
update 表1 set 表1.total_jx=表2.total_jx from 表1 ,表2 where 表1.cs=表2.cs
update 表1 set a表1.total_dz=表3.total_dz from 表1 ,表3 where 表1.cs=表3.cs
orcale 2003-10-20
  • 打赏
  • 举报
回复
insert into 表1 select * from 表2 union all select * from 表3

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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