当前位置: 代码迷 >> Sql Server >> 更新一张表的列,却需要比较比较另一张表的3列取出这列的SQL语句。该如何处理
  详细解决方案

更新一张表的列,却需要比较比较另一张表的3列取出这列的SQL语句。该如何处理

热度:83   发布时间:2016-04-27 14:53:01.0
更新一张表的列,却需要比较比较另一张表的3列取出这列的SQL语句。
现在是这样的情况 A表中有一列 X
  B表中有三列 D,E,F


需要写个Update 的语句, 我要比较D,E,F 取出里面的最大值,就是取出3列中每一行的最大值, 然后把这个值 Update到X中。


用一条SQL语句怎么写? 拜托了。

------解决方案--------------------
SQL code
update a set x = (select max(y) from (select max(d) as y from bunion all select max(e) as y from bunion all select max(f) as y from b) as t)
------解决方案--------------------
SQL code
update a set x = (select max(y) from (select d as y from b where id=a.idunion all select e as y from b  where id=a.idunion all select f as y from b  where id=a.id) as t)
  相关解决方案