我有一个场景,我想计算一周结束日期(给定一个日期),考虑到星期六结束。我读了一些答案,但找不到解决办法,所以我把我的方法贴在这里。希望它能帮助像我这样的人。
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条答案
按热度按时间k4aesqcs1#