0

我想删除此查询返回的记录:

SELECT SQL_CALC_FOUND_ROWS tag, COUNT( tag ) AS count
FROM _tags
GROUP BY tag
HAVING count = 1
ORDER BY count DESC
LIMIT 100;

我怎样才能做到这一点?

4

1 回答 1

1

假设tag_tags'主键:

DELETE _tags.* FROM _tags
JOIN ( 
    SELECT tag FROM _tags GROUP BY tag HAVING COUNT(tag) = 1 LIMIT 100
) AS subq USING (tag)

不确定“按 SQL_CALC_FOUND_ROWS 删除”是什么意思。如果您只想知道有多少记录符合您的条件而忽略该LIMIT子句,那么您应该先运行一个SELECT

于 2013-06-20T06:47:22.903 回答