我正在尝试在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 ;
它给我一个错误
编译语句时出错:FAILED:ParseException 4:85不匹配的输入'AS'期待KW_END在'end'附近表达式
答案 0 :(得分:1)
Nested case statements
中, hive
有点棘手。它应该是这样的: -
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 ;