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
    */
  • 相关阅读:
    最长公共上升子序列
    最长公共子序列
    3847: Mowing the Lawn (单调队列)
    A/B(扩展欧几里得)
    One Person Game(扩展欧几里得)
    Substring with Concatenation of All Words, 返回字符串中包含字符串数组所有字符串元素连接而成的字串的位置
    Divide two numbers,两数相除求商,不能用乘法,除法,取模运算
    Merge k Sorted Lists, k路归并
    二路归并排序,利用递归,时间复杂度o(nlgn)
    StrStr,判断一个字符串是不是另一个字符串的字串,并返回子串的位置
  • 原文地址:https://www.cnblogs.com/wangdrama/p/14789611.html
Copyright © 2011-2022 走看看