我有一个项目表和另一个报告。每个报告都有一个外键链接到正在报告的项目。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