【hivesql】找出正常日期

select出正常的birthday及其它字段,异常的birthdayselect时 id_number、birthday  输出为空,不是更改

1.union分情况

select accountname, '' as birthday, dt, gender, '' as id_number, modify_time
from xsj_acc_real_identity_en
where dt = '2022-07-10'
and birthday not rlike '([1][9]|[2][0])([0-9]{2})-([1-9]|(0[1-9])|1[0-2])-([1-9]|(0[1-9])|([1-2][0-9])|30|31)$'
union all
select *
from xsj_acc_real_identity_en
where dt = '2022-07-10'
and birthday rlike '([1][9]|[2][0])([0-9]{2})-([1-9]|(0[1-9])|1[0-2])-([1-9]|(0[1-9])|([1-2][0-9])|30|31)$'

2.case when

select accountname, dt, gender, modify_time,
case when birthday rlike '([1][9]|[2][0])([0-9]{2})-([1-9]|(0[1-9])|1[0-2])-([1-9]|(0[1-9])|([1-2][0-9])|30|31)$' then birthday
  else '' end as birthday,
case when birthday rlike '([1][9]|[2][0])([0-9]{2})-([1-9]|(0[1-9])|1[0-2])-([1-9]|(0[1-9])|([1-2][0-9])|30|31)$' then id_number
  else '' end as id_number
from xsj_acc_real_identity_en
where dt = '2022-07-10'

猜你喜欢

转载自blog.csdn.net/weixin_43955488/article/details/125907260