首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL去掉反复数据只留一条

2013-03-01 
SQL去掉重复数据只留一条select distinct khh,khjlh,jlrq into zj_khh_khjlh from crmo_yxzc_khdygx where

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)

热点排行