• MYSQL 当有两条重复数据时 保留一条


    delete from test  where id in (select id from (select  max(id) as id,count(text) as count from test group by text having count >1 order by count desc) as tab )


    测试代码


     INSERT IGNORE INTO test_1(text,text2) values ('1111','22222');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','22222');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','22222');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','22222');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','22222');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('1111','33333');

     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');
     INSERT IGNORE INTO test_1(text,text2) values ('22222','33333');


     REPLACE  INTO test(text) values ('1111')

    delete from test

    select * from test_1 where text='1111'
    select * from test_1 where text='22222'

    while 
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );

    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );
    delete from test_1  where id in (select id from (select  max(id) as id,count(text) as count from test_1 where text = '22222' group by text,text2 having count >1 order by count desc) as tab );





  • 相关阅读:
    Win8 iis 环境搭建
    Windows phone 8 触发器使用小结
    Windows Phone 页面之间参数传递方法
    日期SQL 脚本
    net 内存泄露和内存溢出
    Emacs的一些事情(与Vi的争议及使用)
    matlab与示波器连接及电脑连接
    msp430学习笔记-TA
    28个Unix/Linux的命令行神器
    linux在线中文手册
  • 原文地址:https://www.cnblogs.com/yilongm/p/4742875.html
Copyright © 2020-2023  润新知