方法是:获取当前日期的下一个星期一,然后再减4天
year(date_sub(next_day('2015-01-01','monday'),4))*100 + weekofyear('2015-01-01')
减4的原因:这周哪年的天数多,就属于哪年。结合以下两张图和sql,就能明白
hive> select year(date_sub(next_day('2015-01-01','monday'),4))*100 + weekofyear('2015-01-01'); 201501 hive> select year(date_sub(next_day('2014-12-31','monday'),4))*100 + weekofyear('2014-12-31'); 201501 hive> select year(date_sub(next_day('2016-01-01','monday'),4))*100 + weekofyear('2016-01-01'); 201553 hive> select year(date_sub(next_day('2015-12-31','monday'),4))*100 + weekofyear('2015-12-31'); 201553
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)