mysql刪除重複數據只保留一條

按照case_sign 分組,保留ID最小的一行記錄sql

DELETE
FROM
    COURT_CASE_DATA
WHERE
    case_sign IN (
    SELECT case_sign FROM (
        SELECT
            case_sign
        FROM
            COURT_CASE_DATA
        GROUP BY
            case_sign
        HAVING
            COUNT(id) > 1
    ) AS tab1
    )
AND id NOT IN (
    SELECT id FROM (
        SELECT
        MIN(id) AS id 
        FROM
        COURT_CASE_DATA
        GROUP BY
        case_sign
        HAVING
        COUNT(id) > 1
    ) AS tab2
)
相關文章
相關標籤/搜索