Mysql_01_mysql方法合集

1. 秒级别时间戳

select unix_timestamp(now());

2.当前时间戳

select current_timestamp();

3. 毫秒级时间戳:

REPLACE(unix_timestamp(current_timestamp(3)),'.','');

4.删除一张表重复记录只保留一条

DELETE a
FROM
    test1 a,
    (
        SELECT
            c. SUBJECT,
            c.RECEIVER,
            max(c.id) AS bid
        FROM
            test1 c
        WHERE
            STATUS = 0
        GROUP BY
            RECEIVER,
            SUBJECT
        HAVING
            count(1) > 1
    ) b
WHERE
    a. SUBJECT = b. SUBJECT
AND a.RECEIVER = b.RECEIVER
AND a.id < b.bid;

案例:
DELETE a
FROM
    s_community a,
    (
        SELECT
            c.name,
            max(c.community_id) AS bid
        FROM
            s_community c
        GROUP BY
            name
        HAVING
            count(1) > 1
    ) b
WHERE
 a.name = b.name
AND a.community_id < b.bid;
原文地址:https://www.cnblogs.com/asndxj/p/14309619.html