当尝试更新以在先前制作的表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;
答案 0 :(得分:0)
您是否尝试过使用WITH
对象?
With updateSyn As
(
...
)
Update updateSyn set ...
SQL Server: UPDATE a table by using ORDER BY
答案 1 :(得分:0)
我使用了一种解决方法,现在它完成了必须做的事情。
UPDATE Abonnement as a
JOIN FietsType AS af ON a.FietsType_FType = af.FType
JOIN AbonnementType AS at ON a.AbonnementType_ATypeId = at.ATypeId
JOIN (SELECT MAX(AbonnementId) as max_id FROM Abonnement) as aa ON a.AbonnementId = aa.max_id
SET a.prijs = af.Prijs * (at.eindDatum + at.beginDatum)