仅在Oracle SQL中的案例上工作天



我在查询中执行了以下情况:

 WHEN phases is null and INSERTIONDATE is null and Priority = 1 and Complexity = 'minor' THEN trunc(CreationDate)+2

但我想增加+2工作日。我怎样才能做到这一点?

示例:假设我们有一个ID,插入日期为NULL,优先级为1次,创建日期为2016年1月15日星期五。输出应为:

115   prio1   minor  acknowledge_date 19/01/2016

这完全是在黑暗中拍摄的,但你提到你想增加两个工作日,你给出的例子(1月16日+2个工作日=1月19日)告诉我你的意思是你想跳过周末。如果是这样的话,我认为这样的东西可能会起作用:

select
  case
    when phases is null and
      insertiondate is null and
      priority = 1 and
      complexity = 'minor' then
        case to_char(creationdate, 'D')
          when '5' then to_char(creationdate + 4, 'DD/MM/YYYY')
          when '6' then to_char(creationdate + 4, 'DD/MM/YYYY')
          when '7' then to_char(creationdate + 3, 'DD/MM/YYYY')
          else to_char(creationdate + 2, 'DD/MM/YYYY')
        end
  end
from test

从本质上讲,我是在做一个穷人的、残酷的工作日计算,即周四和周五,2个工作日=4个日历日,周六,2个营业日=3个日历天,所有其他日子,2天=2天。

如果这没有切中要害,我不会感到震惊,但也许这是澄清的起点。

对于接下来的创建日,它将返回以下结果:

Creation date           Result
1/15/2016 9:28:31 AM    19/01/2016
1/16/2016 9:41:49 AM    19/01/2016
1/17/2016 9:41:51 AM    19/01/2016
1/18/2016 9:41:52 AM    20/01/2016
1/19/2016 9:41:54 AM    21/01/2016
1/21/2016 9:42:00 AM    25/01/2016

最新更新