如何在配置单元中使用星期六作为周结束日期来计算周结束日期?

6ioyuze2  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(373)

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

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;
k4aesqcs

k4aesqcs1#

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;

相关问题