我有一個項目表和另一個報告。每個報告都有一個外鍵鏈接到正在報告的項目。MySQL DELETE語句加入,HAVING和GROUP BY
我試圖刪除這個查詢中顯示的所有項目:
SELECT items.id, title, SUM(weight) AS total_weight, SUM(weight)*10/views AS score
FROM items, reports
WHERE items.id = reports.item_id
GROUP BY items.id
HAVING score >= 50;
嘗試這樣的事:
DELETE items
FROM (SELECT items.id, title, SUM(weight) AS total_weight, SUM(weight)*10/views AS score
FROM items, reports
WHERE items.id = reports.item_id
GROUP BY items.id
HAVING score >= 50)
AS T;
給我此錯誤消息:
ERROR 1109 (42S02): Unknown table 'items' in MULTI DELETE
謝謝,戈登。權重來報告,但意見與項目。你的意思是把項目別名在前? – mukama
謝謝戈登。非常翔實的答案,但由於某種原因沒有執行。@var ___的答案爲我工作。再次感謝。 – mukama