SQL 基础语法整理

update select 之后的数据

update B set B_account = b.s_amount from B a, ( select sum(amount) as s_amount,pay_id from A group by pay_id ) b where a.pay_id = b.pay_id select name from (select name,avg(score) as a_score from student where name like '张%' group by name) a where a.a_score > 75

可以看出Mysql、Sybase、SQL SERVER的解决办法是使用UPDATE…SET…FROM…WHERE…的语法,实际上就是从源表获取更新数据。
注意:from后面是两个表的连接,源表+查询结果表。

oracle、DB2中:

UPDATE A SET (A1, A2, A3) = (SELECT B1, B2, B3 FROM B WHERE A.ID = B.ID) WHERE ID IN (SELECT B.ID FROM B WHERE A.ID = B.ID) UPDATE A SET (A1, A2, A3) = (SELECT B1, B2, B3 FROM B WHERE A.ID = B.ID)

可以看出,后面的查询只是查询的一张表。

你可能感兴趣的:(sql)