查詢 text 表中,user_name欄位值重覆的數據及重覆次數 刪除 text 表中,重覆出現的數據只保留 ID 最小的一條數據,沒有重覆的數據不刪除。 ...
查詢 text 表中,user_name欄位值重覆的數據及重覆次數
select user_name,count(*) as count from text group by user_name having count>1
刪除 text 表中,重覆出現的數據只保留 ID 最小的一條數據,沒有重覆的數據不刪除。
delete from text where DW_DATE=20171227 AND id not in( select id from (select max(id) as id,count(user_name) as count from text WHERE DW_DATE=20171227 group by user_name having count =1 order by count desc) as tab) AND id not in( select id from (select max(id) as id,count(user_name) as count from text WHERE DW_DATE=20171227 group by user_name having count >1 order by count desc) as tab)