0%

sql快速去重

1
DELETE consum_record
2
FROM
3
    consum_record, 
4
    (
5
        SELECT
6
            min(id) id,
7
            user_id,
8
            monetary,
9
            consume_time
10
        FROM
11
            consum_record
12
        GROUP BY
13
            user_id,
14
            monetary,
15
            consume_time
16
        HAVING
17
            count(*) > 1
18
    ) t2
19
WHERE
20
    consum_record.user_id = t2.user_id 
21
    and consum_record.monetary = t2.monetary
22
    and consum_record.consume_time  = t2.consume_time
23
AND consum_record.id > t2.id;

抄自https://www.cxiansheng.cn/server/348