可以使用以下SQL语句删除每个User超出1000条的Notification:

DELETE FROM Notification
WHERE id IN (
    SELECT id
    FROM (
        SELECT n.id, n.user_id, COUNT(*) AS count
        FROM Notification AS n
        GROUP BY n.id, n.user_id
        HAVING count > 1000
    ) AS subquery
)

这个SQL语句使用子查询来获取每个User超出1000条的Notification的id,然后将这些id传递给外部的DELETE语句来删除这些Notification。

sql 有 User 表和 Notification 表现在要删除每个User 超出 1000 条的 Notification

原文地址: https://www.cveoy.top/t/topic/iNb6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录