我有以下查询:
select count(*)
FROM
cumul AS t1,
cumul AS t2
WHERE
t1.id+1 = t2.id
and
t2.spec_datetime-t1.spec_datetime < 0.001
and
t1.id < 100000
and
t1.v1-t2.v1 = 0
and
t1.v2-t2.v2 =0;
我想删除相同的记录:
DELETE FROM cumul AS t1, cumul AS t2
WHERE
t1.id+1 = t2.id
and
t2.spec_datetime-t1.spec_datetime < 0.001
and
t1.v1-t2.v1 = 0
and
t1.v2-t2.v2 = 0;
我得到:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS t1 , cumul AS t2 WHERE t1.id+1 = t2.id and t2.spec_datetime-t1.spec_datetime <' at line 1
如何更正查询?
最佳答案
DELETE t1 FROM cumul AS t1, cumul AS t2 ^^ Just add alias before FROM
So try this:
DELETE t1 FROM cumul AS t1, cumul AS t2
WHERE
t1.id+1 = t2.id
and
t2.spec_datetime-t1.spec_datetime < 0.001
and
t1.v1-t2.v1 = 0
and
t1.v2-t2.v2 = 0;
引用MySQL :: 13.2.2. DELETE Syntax获取更多信息。
关于mysql删除连续的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12066357/