如何使用星期六作为星期结束日期计算蜂巢中的星期结束日期?

时间:2016-03-03 14:22:19

标签: sql date hadoop hive dayofweek

我有一个场景,我想计算一周的结束日期(给定一个日期),考虑周六的周结束。我读了一些答案,但找不到解决方案,所以我在这里发布我的方法。希望它能帮到像我这样的人。

select 
TransactionDateTime,
from_unixtime(unix_timestamp(TransactionTime),'u') as wkday,
date_add (TransactionDateTime,
case when from_unixtime(unix_timestamp(TransactionTime),'u')=7 then 6 
when from_unixtime(unix_timestamp(TransactionTime),'u')=1 then 5
when from_unixtime(unix_timestamp(TransactionTime),'u')=2 then 4
when from_unixtime(unix_timestamp(TransactionTime),'u')=3 then 3
when from_unixtime(unix_timestamp(TransactionTime),'u')=4 then 2
when from_unixtime(unix_timestamp(TransactionTime),'u')=5 then 1
when from_unixtime(unix_timestamp(TransactionTime),'u')=6 then 0
end) as UsageWkEndDt
from TransTable;

1 个答案:

答案 0 :(得分:0)

select 
TransactionDateTime,
from_unixtime(unix_timestamp(TransactionTime),'u') as wkday,
date_add (TransactionDateTime,
case when from_unixtime(unix_timestamp(TransactionTime),'u')=7 then 6 
when from_unixtime(unix_timestamp(TransactionTime),'u')=1 then 5
when from_unixtime(unix_timestamp(TransactionTime),'u')=2 then 4
when from_unixtime(unix_timestamp(TransactionTime),'u')=3 then 3
when from_unixtime(unix_timestamp(TransactionTime),'u')=4 then 2
when from_unixtime(unix_timestamp(TransactionTime),'u')=5 then 1
when from_unixtime(unix_timestamp(TransactionTime),'u')=6 then 0
end) as UsageWkEndDt
from TransTable;