hive sql 對一天的數據按5分鍾進行分段


背景:離線的數據中有時間戳,要求按五分鍾規划為一組00:00 - 23:55

 

 

 1.cast(date_format(t1.order_end_time,'HH') as string)把小時拿出來

 2.(floor(date_format(t1.order_end_time,'mm')/5 )*5) as string 把分鍾數除5,24/5=4.8。再向下取整=4。再乘5=20。

 3.case when判斷如果結果是0就得00,5就得05

 4.最后concat_ws拼接小時和分鍾

 

concat_ws(':',cast(date_format(t1.order_end_time,'HH') as string)
,case when cast((floor(date_format(t1.order_end_time,'mm')/5 )*5) as string) = '0' then '00'
when cast((floor(date_format(t1.order_end_time,'mm')/5 )*5) as string) = '5' then '05'
else cast((floor(date_format(t1.order_end_time,'mm')/5 )*5) as string) end) as '分鍾段'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM