gpt4 book ai didi

mysql - 使用 where 子句删除 MySQL 行

转载 作者:可可西里 更新时间:2023-11-01 08:10:57 25 4
gpt4 key购买 nike

我正在尝试根据某些文件删除重复的行。当我运行以下查询时:

delete
from slowmo_vid as sv1, slowmo_vid as sv2
where sv1.video_id = '2luh6g3ni5ex'
and sv1.slowmo_end_t<=sv2.slowmo_end_t;

我收到错误:

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 sv1, slowmo_vid as sv2
where sv1.video_id = '2luh6g3ni5ex'
and sv1.slowmo_end' at line 2

表格的字段是:id, video_id internal_uri, slowmo_end_t

最佳答案

您似乎试图在 DELETE 语句中执行 ANSI-92 样式的内部联接。但是WHERE 子句不能同时用于强制连接 对结果集强制限制。相反,执行以下显式 INNER JOIN 以删除您想要的记录。请注意,WHERE 子句的作用一目了然。

更新:如果您想要删除包含最大 video_id 的记录除外,那么您可以将嵌套子查询添加到 WHERE 子句。

DELETE sv1.*
FROM slowmo_vid sv1
INNER JOIN slowmo_vid sv2 ON sv1.slowmo_end_t <= sv2.slowmo_end_t
WHERE sv1.video_id = '2luh6g3ni5ex' AND
sv1.video_id <> (SELECT x.id
FROM (SELECT MAX(t.video_id) AS id
FROM slowmo_vid t) x)

关于mysql - 使用 where 子句删除 MySQL 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34129947/

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