mysql 一些语句

2021/5/20 19:29:32

本文主要是介绍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
*/

 



这篇关于mysql 一些语句的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程