返回日记本

SQL去掉重复数据只留一条

select distinct khh,khjlh,jlrq into zj_khh_khjlh from crmo_yxzc_khdygx where gxlx='01'    select khh,khjlh,jlrq,rank()over(order by khh,jlrq desc,khjlh) as rankno  into zj_khh_khjlh_cf from zj_khh_khjlh where khh in (  select khh from zj_khh_khjlh group by khh having count(1)>1)    delete from zj_khh_khjlh where khh in (  select khh from zj_khh_khjlh group by khh having count(1)>1)    insert into zj_khh_khjlh   select khh,khjlh,jlrq from zj_khh_khjlh_cf a where not exists (select 1 from zj_khh_khjlh_cf b where a.khh = b.khh and a.rankno>b.rankno)




0 顶0 踩


原文章浏览量:1698

原文章分类:数据库

原文链接:https://www.iteye.com/blog/lizhiyu-1816614