有没有办法在黑斑羚中添加和减去日期中的天数
我有要求,其中表 A 具有 cont_number、start_dates 和 end_dates 并且 表 B 具有 cont_number,numberofdays(具有 + 和 - 值的天数,例如:30、-20) 表 A:
cont_number | start_date | end_date |
---|---|---|
276820 | 2021年7月1日 2021年 | 7月31日 |
817689 | 2021年 | 6月1日 2021年6月30日 |
827628 | 2021年9月01 | 日 2021年9月30日 |
表-B
cont_number | Numberofdays |
---|---|
276820 | -30 |
817689 | 40 |
827628 | 20 |
如果表 B Numberofdays 具有 +ve 值,则应将这些天添加到表 A 的 end_date 中,如果是 -ve 值,则应添加到 start_date 请帮助我满足以下要求
期望输出:
cont_number | start_date | end_date | new_start_date | new_end_date |
---|---|---|---|---|
276820 | 01-Jul-2021 | 31-Jul-2021 | 01-Jun-2021 | 31-Jul-2021 |
817689 | 01-Jun-2021 | 30-Jun- 2021年 | 2021年6月1日 2021 | 年8月9日 |
827628 | 2021年9月1 | 日 2021年9月30日 2021 | 年9月 | 1日 2021年10月20日 |
I have requirement where table A is having the cont_number,start_dates and end_dates and
table B is having cont_number,numberofdays(numbers of days having + and - values eg:30,-20)
Table A:
cont_number | start_date | end_date |
---|---|---|
276820 | 01-Jul-2021 | 31-Jul-2021 |
817689 | 01-Jun-2021 | 30-Jun-2021 |
827628 | 01-Sep-2021 | 30-sep-2021 |
Table-B
cont_number | Numberofdays |
---|---|
276820 | -30 |
817689 | 40 |
827628 | 20 |
If Table B Numberofdays having +ve value it should add those days to end_date of Table-A and if it is -ve value then it should add to start_date
Please help me with this below requirement
Expecting output:
cont_number | start_date | end_date | new_start_date | new_end_date |
---|---|---|---|---|
276820 | 01-Jul-2021 | 31-Jul-2021 | 01-Jun-2021 | 31-Jul-2021 |
817689 | 01-Jun-2021 | 30-Jun-2021 | 01-Jun-2021 | 09-Aug-2021 |
827628 | 01-Sep-2021 | 30-sep-2021 | 01-Sep-2021 | 20-Oct-2021 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以在 impala 中使用
if
或case-when
。new_start_date 的计算方式为:Numberofdays >=0,然后 end_date + Numberofdays,否则使用原始开始日期。
new_end_date 的计算方式为:如果 Numberofdays <0,则 start_date + Numberofdays,否则使用原始结束日期。
you can use
if
orcase-when
in impala.new_start_date is calculated as if Numberofdays >=0 then end_date + Numberofdays else use original start date.
new_end_date is calculated as if Numberofdays <0 then start_date + Numberofdays else use original end date.