[hivesql] Find out the normal date

Select the normal birthday and other fields, when the abnormal birthday is selected, the output of id_number and birthday is empty, not a change

1.Union points the situation

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'

Guess you like

Origin blog.csdn.net/weixin_43955488/article/details/125907260