首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-13 
更新一张表的列,却需要比较比较另一张表的3列取出这列的SQL语句。现在是这样的情况A表中有一列XB表中有三列

更新一张表的列,却需要比较比较另一张表的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) 

热点排行