Home  >  Article  >  Database  >  删除表中重复记录大于两条保存两条

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

WBOY
WBOYOriginal
2016-06-07 14:57:43987browse

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 )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn