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)