Db2 数据防空,判断重复数据并且去重复

--- 如果s_prepfieldtwo字段值为空则取字段 s_prepfieldone的值

select  value(s_prepfieldtwo,s_prepfieldone) s_prepfieldtwo  from  TA_table_name where s_orgcode='230000000002'

select  coalesce (s_prepfieldtwo,s_prepfieldone) s_prepfieldtwo  from  TA_table_name where s_orgcode='230000000002'

---利用count(必须有列函数group by )函数看是否有重复数据

select  S_BOOKORGCODE, S_PAYERACCT , count(*) from  TA_table_name   where 1=1 group  by S_BOOKORGCODE, S_PAYERACCT  having  count(*) >1;

--- 利用distinct函数和min函数进行数据去重复

SELECT distinct S_BOOKORGCODE,min (S_PAYERNAME)as S_PAYEENAME ,S_PAYERACCT,min (S_ENROLERID)as S_ENROLERID ,min (S_BANKTYPE) as S_BANKTYPE

    FROM  TA_table_name    group by S_BOOKORGCODE,S_PAYERACCT

猜你喜欢

转载自blog.csdn.net/m0_37604866/article/details/81004239
今日推荐