-- 部署 jituan 前若 migrate 报 Duplicate entry 唯一约束冲突，在 dbshell 执行。
-- 每种组合只保留 id 最大的一条；不影响订单/资金主表。

-- config.0006 tupianpeizhi
DELETE FROM tupianpeizhi
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM tupianpeizhi GROUP BY club_id, ImageType
    ) AS t
);

-- config.0006 popup_page
DELETE FROM popup_page
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM popup_page GROUP BY club_id, page_key
    ) AS t
);

-- products.0005 duoci_fenhong
DELETE FROM duoci_fenhong
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM duoci_fenhong GROUP BY club_id, huiyuan, yonghuid, cishu
    ) AS t
);

-- backend.0003 提现日统计
DELETE FROM tixian_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM tixian_ri_tongji GROUP BY club_id, Date, WithdrawalType
    ) AS t
);

-- backend.0004 角色日统计
DELETE FROM shangjia_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM shangjia_ri_tongji GROUP BY club_id, MerchantID, Date
    ) AS t
);
DELETE FROM dashou_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM dashou_ri_tongji GROUP BY club_id, PlayerID, Date
    ) AS t
);
DELETE FROM zuzhang_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM zuzhang_ri_tongji GROUP BY club_id, LeaderID, Date
    ) AS t
);
DELETE FROM guanshi_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM guanshi_ri_tongji GROUP BY club_id, ManagerID, Date
    ) AS t
);
DELETE FROM guanshi_xufei_ri_tongji
WHERE id NOT IN (
    SELECT keep_id FROM (
        SELECT MAX(id) AS keep_id FROM guanshi_xufei_ri_tongji GROUP BY club_id, ManagerID, Date
    ) AS t
);

-- szjilu 应只有 1 行；多行时勿自动删，需人工核对 TotalIncome 后处理
