gpt4 book ai didi

mysql删除连续的行

转载 作者:行者123 更新时间:2023-11-29 00:41:34 26 4
gpt4 key购买 nike

我有以下查询:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com