嵌套大小写错误:大小写表达式:配置单元中的输入“as”不匹配,应在“end”附近找到kw\u end

hl0ma9xz  于 2021-06-29  发布在  Hive
关注(0)|答案(1)|浏览(398)

我想在Hive里执行这个案子

select case when (hour(rand_date)>=0 and hour(rand_date)<6) then 'early_morning' else 
case when (hour(rand_date)>=6 and hour(rand_date)<12) then 'morning' else 
case when (hour(rand_date)>=12 and hour(rand_date)<18) then 'afternoon' else
case when (hour(rand_date)>=18 and hour(rand_date)<24) then 'night' else 'other' end AS hourbins,
 rand_date from mock_ads_dates ;

这给了我一个错误
编译语句时出错:失败:parseexception行4:85不匹配的输入“as”,在case表达式中应为“end”附近的kw\u end

368yc8dk

368yc8dk1#

Nested case statements 有点棘手 hive . 应该是这样的this:-

select case when (hour(rand_date)>=0 and hour(rand_date)<6) then 'early_morning' 
when (hour(rand_date)>=6 and hour(rand_date)<12) then 'morning'
when (hour(rand_date)>=12 and hour(rand_date)<18) then 'afternoon'
when (hour(rand_date)>=18 and hour(rand_date)<24) then 'night' else 'other' end AS hourbins,rand_date from mock_ads_dates ;

相关问题