语法: CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END

说明:如果a为TRUE,则返回b;如果c为TRUE,则返回d;否则返回e

实例

hive> case when salary is null  then "- -" else salary end from stg_job
#salary为空则转换成 - -,不是则不做改变

hive> case when (job_location like '%北京%' = true) then 'A1' else 'A9' end from s_job
#将job_location字段为北京返回A1,否则返回A9
语法: CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END

说明:如果a等于b,那么返回c;如果a等于d,那么返回e;否则返回f

实例

hive> Select case 100 when 50 then 'a' when 100 then 'b'else 'c' end from wujiadong;
#如果100等于50返回a,等于100返回b,都不是返回c

相关文章:

  • 2021-07-01
  • 2022-01-15
  • 2022-01-29
  • 2022-12-23
  • 2022-02-07
  • 2021-11-25
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-08-16
  • 2021-06-18
相关资源
相似解决方案