带 GROUP BY 无法用于update SQL语句吗 以下SQL 没问题,正确,但是我的目的是更新 SELECT A.Epuid,MAX(B.intb),SUM(C.intb) FROM Frdrecordson A LEFT JOIN Epurchaseson B on A.Epuid=B.ID LEFT JOIN Frdrecordson C on A.Epuid=C.Epuid WHERE A.stcode='A1205-0013' AND A.Epuid>0 GROUP BY A.Epuid HAVING SUM(C.intb)>=MAX(B.intb)
所以我演变如下SQL语句 UPDATE B SET B.stsb = '结束' FROM Frdrecordson A LEFT JOIN Epurchaseson B on A.Epuid=B.ID LEFT JOIN Frdrecordson C on A.Epuid=C.Epuid WHERE A.stcode='A1205-0013' AND A.Epuid>0 GROUP BY A.Epuid HAVING SUM(C.intb)>=MAX(B.intb)
UPDATE B
SET B.stsb = '结束'
FROM b
inner join (SELECT A.Epuid,MAX(B.intb),SUM(C.intb)
FROM Frdrecordson A
LEFT JOIN Epurchaseson B on A.Epuid=B.ID
LEFT JOIN Frdrecordson C on A.Epuid=C.Epuid
WHERE A.stcode='A1205-0013' AND A.Epuid>0
GROUP BY A.Epuid
HAVING SUM(C.intb)>=MAX(B.intb)) A on A.epuid=b.id
------解决方案--------------------