AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 冻结用户(激活) | Residents

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
       
Title: mysql 查询x表posts字段,删除重复的值&同一日的数据只保留posts最大的那条  
  This topic was added by com at 2024-11-22 11:53 移动 
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3869
码币MB 2619 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
mysql 查询x表posts字段,删除重复的值&同一日的数据只保留posts最大的那条

mysql 查询x表posts字段,删除重复的值

DELETE FROM X
WHERE id NOT IN (
    SELECT * FROM (
        SELECT MAX(id)
        FROM X
        GROUP BY posts
    ) AS temp
);
day字段类型为timestamp,同一日的数据只保留posts最大的那条。

DELETE t1
FROM X t1
JOIN (
    SELECT DATE(day) AS date, MAX(posts) AS max_posts
    FROM X
    GROUP BY DATE(day)
) t2 ON DATE(t1.day) = t2.date AND t1.posts < t2.max_posts;
[ 本帖最后由 sky999 于 2023-7-16 15:01 编辑 ]




CAFFZ.com
2023-7-16 14:53#1
View profile  Blog  Send a short message  Top
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2025-6-27 14:40 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE