更新一张表的列,却需要比较比较另一张表的3列取出这列的SQL语句。
现在是这样的情况 A表中有一列 X
B表中有三列 D,E,F
需要写个Update 的语句, 我要比较D,E,F 取出里面的最大值,就是取出3列中每一行的最大值, 然后把这个值 Update到X中。
用一条SQL语句怎么写? 拜托了。
[解决办法]
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)
[解决办法]
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)