2
我有這樣的查詢
目標表...的DELETE是不可更新
SET @n=0;
DELETE t3 FROM (
SELECT id, project_id, task_id, user_id,grouper
FROM (
SELECT id, project_id, task_id, user_id,
@n:=if(status=55,@n+1,@n),
if(status=55,@n-1,@n) as grouper FROM timelog
WHERE user_id='5' ORDER BY id ASC
) as t
where grouper>-1
group by grouper) as t3 WHERE grouper=1
爲此我收到The target table t3 of the DELETE is not updatable
是有這個錯誤的任何解決方案?
基本上我想要的是刪除使用選擇刪除標記爲grouper
的錶行組。我也很高興與其他解決方案或想法不同。
SQL小提琴:http://sqlfiddle.com/#!2/33820/2/0
編輯:感謝這裏的答案是工作代碼(如果有人需要類似的東西):
SET @n=0;
delete from timelog where id in ((SELECT id
FROM (
SELECT id, project_id, task_id, user_id,
@n:=if(status=55,@n+1,@n),
if(status=55,@n-1,@n) as grouper FROM timelog
WHERE user_id='5' ORDER BY id ASC
) as t
where grouper>-1 and grouper=1
group by grouper))
您是否試圖從數據庫表中刪除記錄? –
通常,您在這裏完成的任務會讓您感到困惑...您想從子選擇語句中刪除? – Twelfth
是刪除特定的行使用子選擇和過濾分組別名/生成的列 – mwebber