zoukankan      html  css  js  c++  java
  • mysql 一些语句

    -- 根据媒体ID去重保留最新ID
    -- select * from wx_img_data_index where media_id='4UrAzEM5I_pFkDh4Fg_4iSRZMksxZfnX3VLk7eETmTg';
    
    -- select * from wx_img_data where media_id='4UrAzEM5I_pFkDh4Fg_4iSRZMksxZfnX3VLk7eETmTg';
    
    -- select media_id ,COUNT(1),MAX(id),MIN(id),max(modified_time) from wx_img_data_index where is_deleted = 0 GROUP BY media_id HAVING COUNT(1) > 1 ;
    
    select a.* from wx_img_data_index a join (select media_id, max(id) as id from wx_img_data_index b where b.is_deleted=0 GROUP BY b.media_id HAVING COUNT(1) > 1) as c on a.media_id = c.media_id  where a.Id<> c.id order by c.media_id;
    
    -- update wx_img_data_index a join (select media_id, max(id) as id from wx_img_data_index b where b.is_deleted=0 GROUP BY b.media_id HAVING COUNT(1) > 1) as c on a.media_id = c.media_id set a.is_deleted=1  where a.Id<> c.id and a.is_deleted <>1 ;
    
    select wx_media_id ,COUNT(1),MAX(id),MIN(id),min(modified_time),max(modified_time) from wx_media where is_deleted = 0 GROUP BY wx_media_id HAVING COUNT(1) > 1 ;
    
    -- update wx_media a join (select wx_media_id, max(id) as id from wx_media b where b.is_deleted=0 GROUP BY b.wx_media_id HAVING COUNT(1) > 1) as c on a.wx_media_id = c.wx_media_id set a.is_deleted=1  where a.Id<> c.id and a.is_deleted <>1 ;
    
    SELECT a.* wx_media a join (select wx_media_id, max(id) as id from wx_media b where b.is_deleted=0 GROUP BY b.wx_media_id HAVING COUNT(1) > 1) as c on a.wx_media_id = c.wx_media_id where a.Id<> c.id and a.is_deleted <>1 order by c.wx_media_id;
    
    /*
    UPDATE wx_app_authorizer a join(
    SELECT phone_number,group_id,ou_id,employee_id,count(1),MAX(id) as id from wx_app_authorizer WHERE is_deleted = 0
    GROUP BY phone_number,group_id,ou_id
    HAVING count(1)>1) as b on a.phone_number = b.phone_number
    set a.is_deleted = 1,a.deleted_by = '手动删除' WHERE a.Id <> b.id and a.is_deleted <> 1;
    */
    
    /*
    ROW_NUMBER() 不重复排名 可以用来分页 1234
    Dense_Rank() 连续相同排序 ,两个第二名仍然跟着第三名 1 2 2 3
    Rank() 跳跃排序,连续相同排序 两个第二名后面跟第四名 1 2 2 4
    SELECT ROW_NUMBER() over(order by _data DESC) rank,data FROM _table
    */
  • 相关阅读:
    田忌赛马 题解
    亚历山大的丢番图方程 题解
    zhx's contest题解
    芝麻OI比赛T7edges题解
    CSP-J2020游记
    Linux shell 学习笔记(五)
    Linux shell 学习笔记(四)
    Linux shell 学习笔记(三)
    Linux shell 学习笔记(二)
    Oracle并发
  • 原文地址:https://www.cnblogs.com/wangdrama/p/14789611.html
Copyright © 2011-2022 走看看