1

我有以下查询:

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):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'AS t1 , cumul AS t2 WHERE t1.id+1 = t2.id 和 t2.spec_datetime-t1.spec_datetime <' 附近使用正确的语法

如何更正查询?

4

2 回答 2

1
从 cumul AS t1 中删除 t1,cumul AS t2  
       ^^
只需在 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。删除语法以获取更多信息。

于 2012-08-22T05:01:16.180 回答
0

您必须指定要从表列表中删除的表(即使在本例中它们是同一个表):

DELETE t1 FROM cumul AS t1, cumul AS t2...

http://dev.mysql.com/doc/refman/5.0/en/delete.html

于 2012-08-22T04:40:28.143 回答