DELETE FROM your_table WHERE id NOT IN ( SELECT MIN(id) FROM your_table GROUP BY comment ) AND comment IN ( SELECT comment FROM your_table GROUP BY comment HAVING COUNT(*) > 1 );没有id这一列怎么办
时间: 2024-03-04 08:51:56 浏览: 79
第二周自测题.docx
如果你的表没有id这一列,你可以使用其他列代替它。比如,你可以使用一个时间戳列或者一个自增列来代替id。在这种情况下,你需要将SQL查询中的id列替换为你选择的列。例如,如果你使用一个名为timestamp的时间戳列,你的SQL查询将如下所示:
DELETE FROM your_table
WHERE timestamp NOT IN (
SELECT MIN(timestamp)
FROM your_table
GROUP BY comment
)
AND comment IN (
SELECT comment
FROM your_table
GROUP BY comment
HAVING COUNT(*) > 1
);
阅读全文