我有以下SELECT查询:
SELECT
T3.EPSINO AS FaktNr,
T3.EPDIVI AS Div,
T3.EPSUNO AS Lev,
T3.EPPYME AS BetMet,
T2.Summa AS Belopp
FROM
M3EDBPTS.FPLEDG T3
JOIN
(SELECT
T1.EPCONO, T1.EPSINO,
T1.EPDIVI, T1.EPSUNO,
SUM(T1.EPCUAM) AS Summa
FROM
M3EDBPTS.FPLEDG T1
WHERE
T1.EPCONO = 001 AND
T1.EPDIVI = '500' AND
T1.EPSUNO = '73823'
GROUP BY
T1.EPCONO,T1.EPDIVI, T1.EPSUNO, T1.EPSINO
HAVING
(SUM(T1.EPCUAM) <> 0)) AS T2 ON T3.EPCONO = T2.EPCONO
AND T3.EPDIVI = T2.EPDIVI
AND T3.EPSINO = T2.EPSINO
AND T3.EPSUNO = T2.EPSUNO
WHERE
T3.EPPYME IN ('KOT', 'ULK')
如何创建脚本来更新我得到的结果?我试着写:
UPDATE T3
SET T3.EPPYME = 'SEP'
FROM M3EDBPTS.FPLEDG T3
JOIN (SELECT
T1.EPCONO, T1.EPSINO, T1.EPDIVI, T1.EPSUNO,
SUM(T1.EPCUAM) AS Summa
FROM M3EDBPTS.FPLEDG T1
WHERE T1.EPCONO = 001 AND T1.EPDIVI = '500' AND
T1.EPSUNO = '73823'
GROUP BY T1.EPCONO, T1.EPDIVI, T1.EPSUNO, T1.EPSINO
HAVING (SUM(T1.EPCUAM) <> 0)) AS T2 ON T3.EPCONO = T2.EPCONO
AND T3.EPDIVI = T2.EPDIVI
AND T3.EPSINO = T2.EPSINO
AND T3.EPSUNO = T2.EPSUNO
WHERE
T3.EPPYME IN ('KOT','ULK')
但我只收到错误:
SQL0199 - 未预期的关键字FROM。有效代币:使用SKIP WAIT WITH WHERE。
语法错误怎么办?
示例DB-table FPLEDG:
答案 0 :(得分:-1)
UPDATE M3EDBPTS.FPLEDG T3
SET T3.EPPYME = 'SEP'
WHERE T3.EPPYME IN ('KOT', 'ULK')
AND EXISTS (
SELECT
T1.EPCONO, T1.EPSINO, T1.EPDIVI, T1.EPSUNO,
SUM(T1.EPCUAM) AS Summa
FROM M3EDBPTS.FPLEDG T1
WHERE T1.EPCONO = 001 AND T1.EPDIVI = '500' AND
T1.EPSUNO = '73823' AND
T3.EPCONO = T1.EPCONO AND
T3.EPDIVI = T1.EPDIVI AND
T3.EPSINO = T1.EPSINO AND
T3.EPSUNO = T1.EPSUNO
GROUP BY T1.EPCONO, T1.EPDIVI, T1.EPSUNO, T1.EPSINO
HAVING (SUM(T1.EPCUAM) <> 0))
这将是攻击的一般计划,但由于我不知道您的数据模型,您将不得不测试它并查看子选择是否正确。