0
我有一個mysql查詢GROUP BY,HAVING。使用GROUP BY寫刪除查詢,HAVING
查詢工作正常,現在需要刪除相同的記錄,當我試圖刪除這些記錄時,我得到一個錯誤。
選擇查詢
SELECT * FROM user_location_history WHERE (TIMESTAMPDIFF(DAY,FROM_UNIXTIME(location_date/1000),SYSDATE())>30) AND user_id IN (SELECT user_id FROM user_location_history WHERE (TIMESTAMPDIFF(DAY,FROM_UNIXTIME(location_date/1000),SYSDATE()) < 30) GROUP BY user_id HAVING COUNT(1) > 100) ORDER BY id ASC LIMIT 200
刪除查詢
DELETE FROM user_location_history WHERE (TIMESTAMPDIFF(DAY,FROM_UNIXTIME(location_date/1000),SYSDATE())>30) AND user_id IN (SELECT user_id FROM user_location_history WHERE (TIMESTAMPDIFF(DAY,FROM_UNIXTIME(location_date/1000),SYSDATE()) < 30) GROUP BY user_id HAVING COUNT(1) > 100) ORDER BY id ASC LIMIT 200
錯誤
錯誤代碼:1093 您不能指定更新目標表 'user_location_history'在FROM子句解決此問題
@Strawberry我的工作在我之前的查詢中使用了GROUP_CONCAT ... –