当尝试更新以在先前的制成表Abonnement中包含价格时,出现标题中提到的错误代码。我在网上四处张望,但看来我的语法正确吗?

SET SQL_SAFE_UPDATES=0;

DELETE FROM Abonnement;
DELETE FROM AbonnementType;

INSERT INTO AbonnementType(beginDatum,eindDatum,type)
VALUES("2013/1/1","2013/1/1","DAGPAS");

INSERT INTO Abonnement(betaald,AbonnementType_ATypeId,FietsType_FType,Klant_klantId,Code,Wachtwoord)
VALUES(false,(SELECT MAX(ATypeId) FROM AbonnementType),1,1,"test","test");

UPDATE Abonnement as a
JOIN FietsType AS af ON a.FietsType_FType = af.FType
JOIN AbonnementType AS at ON a.AbonnementType_ATypeId = at.ATypeId
SET a.prijs = af.Prijs * (at.eindDatum + at.beginDatum)
ORDER BY AbonnementId DESC
LIMIT 1;

最佳答案

您是否尝试过使用WITH对象?
With updateSyn As(...)
Update updateSyn set ...

SQL Server: UPDATE a table by using ORDER BY

关于mysql - 错误代码:1221。UPDATE和ORDER BY的用法不正确—更新表取消时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26217584/

10-11 01:18