2013-08-01 60 views
1

我必須消除所謂的「奧斯卡」的技術人員,誰在 年做維修2010刪除給出錯誤

我必須先刪除它們進行維修,然後刪除名爲「奧斯卡」」技師。我做這兩個語句:

DELETE FROM Reparacion WHERE cuit_tec IN(SELECT Tec.cuit 
      FROM Tecnico Tec 
      WHERE Tec.nombre like 'oscar%' 
      AND NOT EXISTS(SELECT 1 
        FROM Reparacion Rep 
        WHERE Rep.cuit_tec = Tec.cuit 
        AND Fecha BETWEEN '2010-01-01' AND '2010-12-31')); 

DELETE FROM 
    Tecnico AS Tec 
WHERE 
    Nombre like 'oscar%' AND 
    NOT EXISTS (SELECT 
       1 
      FROM 
       Reparacion AS Rep 
      WHERE 
       Rep.Cuit_tec = Tec.Cuit AND 
       Fecha BETWEEN '2010-01-01' AND '2010-12-31'); 

這將引發錯誤信息:

"Error Code: 1093. You can not specify target table 'Repair' for update in FROM clause" 
"Error Code: 1064. You have an error in your SQL syntax, check the Manual That Corresponds to your MySQL server version for the right syntax to use near 'AS Tec WHERE Name = 'oscar' AND NOT EXISTS (SELECT 1 FROM R ' at line 2 " 

sqlfiddle:http://sqlfiddle.com/#!2/9438d

+0

請編輯您的問題,這是不明確的。你想刪除2010年只修復過的奧斯卡技術人員嗎?你想刪除奧斯卡技術人員及其2010年修理,這將使你與2011年等奧斯卡修復等修復不再指向一個生活;-)技術人員? –

+0

如果您只想刪除只有* 2010年修理過的奧斯卡,您必須創建一個臨時表來選擇這些奧斯卡 - 然後根據該臨時表刪除相應的維修和技術人員,然後刪除臨時表。 –

回答

1

是不是錯誤的位置:

WHERE 
    Nombre like= 'oscar%' AND 

得是Nombre like 'oscar%' AND