HIVE使用过程中的问题

1.月份数间隔(注意是月份之间的相减,如“2017-09-01”,“2017-09-31”,是差0个月)

ps:公司的需求是查看客户在本月是否上传(每月上传一次,时间不一定),或者有几个月没上传数据了,因此相差0个月即表示其已经上传过数据了
1)考虑计算月份差的函数:months_between(),但是其返回的是包含多余天数,并将其转为小数;
2)将时间全部转为其月份对应的第一天,即可得到整数的月份数差:
TRUNC函数为指定元素而截去的日期值。
其具体的语法格式如下:
TRUNC(date[,fmt])
其中:date 一个日期值
fmt 日期格式,该日期将由指定的元素格式所截去。忽略它则由最近的日期截去
如果当日日期是:2011-3-18
1.select trunc(sysdate) from dual --2011-3-18 今天的日期为2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1 返回当月第一天.
3.select trunc(sysdate,'yy') from dual --2011-1-1 返回当年第一天
4.select trunc(sysdate,'dd') from dual --2011-3-18 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual --2011-1-1 返回当年第一天
6.select trunc(sysdate,'d') from dual --2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual --2011-3-18 14:00:00 当前时间为14:41
8.select trunc(sysdate, 'mi') from dual --2011-3-18 14:41:00 TRUNC()函数没有秒的精确

猜你喜欢

转载自blog.csdn.net/weixin_34088583/article/details/90959299
今日推荐