Hive使用中常见问题总结(三)

尊敬的读者您好:笔者很高兴自己的文章能被阅读,但原创与编辑均不易,所以转载请必须注明本文出处并附上本文地址超链接以及博主博客地址:https://blog.csdn.net/vensmallzeng。若觉得本文对您有益处还请帮忙点个赞鼓励一下,笔者在此感谢每一位读者,如需联系笔者,请记下邮箱:[email protected],谢谢合作!

一、关于hive对两时间点进行比较

1、两个时间差计算

#返回end_date - start_date的结果
datediff(string end_date,string start_date)

举个例子:计算用户评论时间与到店时间的间隔

select datediff(comment_time, arrive_time) as arrive_comment_interval from hotel_table

2、在一个时间点上增加指定天数

#在start_date的基础上加days天
date_add(string start_date, int days)

3、在一个时间点上增加指定天数

#在start_date的基础上减去days天
date_sub(string start_date, int days)

注:1 - 3均以天为最小计算单位,若要精确到时分秒建议参考:“https://blog.csdn.net/wrty1993/article/details/78548312/” 。

二、对时间点进行取整

用to_date()函数将时间为“2013-09-30 00:00:00”取整为“2013-09-30”

#将ordh_arrive_time进行取整
SELECT unionid, to_date(ordh_arrive_time) as arrive_time from dev_hotel.user_portrait_order_base

日积月累,与君共进,增增小结,未完待续。

发布了152 篇原创文章 · 获赞 147 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/Vensmallzeng/article/details/103895322