當試圖更新以在前面的表Abonnement中包含價格時,我得到標題中提到的錯誤代碼。我在網上四處張望,但似乎我的語法是正確的?錯誤代碼:1221. UPDATE和ORDER BY的錯誤用法 - 當更新表Abornement時
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;