2016-06-10 115 views
0

我想在蜂巢巢式病例錯誤:蜂巢

執行這種情況下
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 ; 

它給了我一個錯誤

Error while compiling statement: FAILED: ParseException line 4:85 mismatched input 'AS' expecting KW_END near 'end' in case expression

:「作爲」預期的情況下,表達KW_END接近「結束」不匹配的輸入

回答

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 ;