日期:2014-05-18  浏览次数:20653 次

更新一张表的列,却需要比较比较另一张表的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 b
union all select max(e) as y from b
union 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.id
union all select e as y from b  where id=a.id
union all select f as y from b  where id=a.id
) as t
)