我有以下查询:
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;
我明白了:
错误1064(42000):您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便在'AS t1附近使用正确的语法 ,cumul AS t2 WHERE t1.id + 1 = t2.id和t2.spec_datetime-t1.spec_datetime&lt;'在 第1行
如何更正查询?
答案 0 :(得分:1)
DELETE t1 FROM cumul AS t1, cumul AS t2 ^^ Just add alias before FROM
所以试试这个:
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。
答案 1 :(得分:0)
您必须指定要删除的表列表中的哪个表(即使它们在此实例中是相同的表):
DELETE t1 FROM cumul AS t1, cumul AS t2...