我有这样的疑问
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
在删除中使用 select 标记的一组表行。我也很高兴看到与此不同的其他解决方案或想法。
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))