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