有没有办法在黑斑羚中加减日期的天数

  • 本文关键字:日期 有没有 sql impala
  • 更新时间 :
  • 英文 :


我有一个要求,其中表A具有cont_number、start_dates和end_dates以及表B具有cont_number,numberofdays(具有+和-值的天数,例如:30,-20(表A:

结束日期2021月31日2021年6月30日2021年9月30日
cont_number 开始日期
276820 2021年7月1日
817689 2021年6月1日
827628 2021年9月1日

您可以在黑斑羚中使用ifcase-when

select 
a.cont_number cont_number,
a.start_date,
a.end_date,
if (b.Numberofdays>= 0 then a.end_date+ interval b.Numberofdays days,a.start_date) new_start_date,
if (b.Numberofdays< 0 then a.start_date+ interval b.Numberofdays days,a.end_date) new_end_date
from tablea A, tableb B
where a.cont_number=b.cont_number

new_start_date被计算为好像Numberofdays>0,则结束日期+天数,否则使用原始开始日期
new_end_date被计算为好像Numberofdays<0,然后开始日期+天数,否则使用原始结束日期。

相关内容

最新更新