我想更新A表的某个字段的值,但是这个值从B 表来的。
因为有很多都要改,我写成下列的却报错??
UPDATE A SET AC = Q.BD
FROM (SELECT BD,BC FROM B group BY BD,BC) AS Q
WHERE A.AC = Q.BC
正确写法是怎样的?
当然报错了,
你这个语法有问题
UPDATE A INNER JOIN (SELECT BD,BC FROM B group BY BD,BC) Q ON A.AC = Q.BC SET A.AC = Q.BD
试试这样可以不
update a ,(SELECT BD,BC FROM B group BY BD,BC) b
set a.AC = b.BD
where A.AC = b.BC
update A set AC= Q.BD from A,Q where A.AC = Q.BC
或者
Update A SET AC= Q.BD FROM A LEFT JOIN Q ON Q.BC=A.AC
试试