• 技术文章 >数据库 >mysql教程

    删除表中重复记录大于两条保存两条

    2016-06-07 14:57:43原创627

    delete from t_Cht_clm_reg F where F.case_id in ( select T.case_id from ( select B.* from (select e.* , row_number() over (partition by e.notice_id order by e.case_id desc) rn from t_Cht_clm_reg e) B where B.notice_id in( select A.notice_id

    delete from t_Cht_clm_reg F where F.case_id in (
    select T.case_id from (
    select B.* from (select e.* , row_number() over (partition by e.notice_id order by e.case_id desc) rn
    from t_Cht_clm_reg e) B where B.notice_id in(
    select A.notice_id from (select e.* , row_number() over (partition by e.notice_id order by e.case_id desc) rn
    from t_Cht_clm_reg e) A group by A.notice_id having count(A.notice_id) > 2 )
    ) T where T.RN > 2 )

    <无>
    delete from t_Cht_clm_reg F where F.case_id in (
    select T.case_id from (
    select  B.* from (select e.* , row_number() over (partition by e.notice_id order by e.case_id desc) rn   
                    from t_Cht_clm_reg e) B where B.notice_id in(
    select  A.notice_id  from  (select e.* , row_number() over (partition by e.notice_id order by e.case_id desc) rn   
                    from t_Cht_clm_reg e) A group by A.notice_id having count(A.notice_id) > 2 )
     ) T where T.RN > 2 )
    
    

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:写在&lt;?php XXXXXXX ?&gt;之间的点击按钮跳转的代码 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • hive和mysql的区别有哪些• mysql数据库的超级管理员名称是什么• mysql怎么连接数据库• mysql事务隔离级别有哪些• count(*)为什么很慢?原因分析
    1/1

    PHP中文网