【问题标题】:SQL query to show if the value has end dated within parameter date rangeSQL查询以显示值是否在参数日期范围内结束日期
【发布时间】:2022-01-14 21:23:07
【问题描述】:

我有一个表格,结果如下deduction_table-

Person_number eff_date eff_end_dt Deduction_taken deduction_amount
12 27/12/2020 01/12/2020 Health Insurance 8.9
13 17/12/2020 31/12/4712 Life Insurance 9
14 18/11/2020 01/01/2021 Sigma 10

当我将参数传递给 25/12/202006/01/2021 时,我应该得到以下结果 -

Person_number change_date Deduction_code deduction_amount
12 02/12/2020 ~Health Insurance 0
13 17/12/2020 Life Insurance 9
14 01/01/2021 ~Sigma 0

所以当我传递参数dates时,我希望如果在传入参数to_date之前有一个effective end date,那么 deduction_amount 是 0 ,deduction_code 应该有 ~ 连接,change_date 是在 end date 之后的第二天。

另外,如果不是这种情况,那么change_Date 应该只是deduction_table 的有效开始。

【问题讨论】:

    标签: sql oracle oracle-sqldeveloper


    【解决方案1】:
    select 
      person_number,
      case when eff_end_dt < incoming_date then eff_end_dt + 1 else eff_date end change_date,
      case when eff_end_dt < incoming_date then '~' end || Deduction_taken     
    
              
    

    应该让你去

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2019-04-26
      • 2017-01-28
      • 1970-01-01
      • 2016-12-16
      • 1970-01-01
      相关资源
      最近更新 更多