select
case
when int(substr(time,1,2))<05 then 1
when int(substr(time,1,2))>=05 and int(substr(time,1,2))<12 then 2
when int(substr(time,1,2))>=12 and int(substr(time,1,2))<18 then 3
when int(substr(time,1,2))>=18 then 4 end apply_period
substr(time,1,8) 表示将time从第1位开始截取,截取的长度为8位,hive的第一个下标是1不是0。
这里感谢xiangzong.