仅当轮班在两个日期时才如何获得轮班日期一个记录?

时间:2018-08-15 07:47:55

标签: sql db2

enter image description here

请检查图像。 如果插入日期和时间,如何获取一条记录?

例如日期= 20180815时间= 231500 仅获取1条记录,什么是轮班日期?

1 个答案:

答案 0 :(得分:0)

您想要这样的东西:

where (shiftstartdate = :datevar and
       :datetime between shiftstarttime and shiftendtime
      ) or
      (shiftenddate = :datevar and
       :datetime between shiftendtime and shiftstarttime
      )

更详细的版本可能使逻辑更清晰:

where (shiftstartdate = :datevar and
       shiftenddate = shiftstartdate and
       shiftstarttime < shiftendtime and
       :datetime between shiftstarttime and shiftendtime
      ) or
      (shiftenddate = :datevar and
       shiftenddate <> shiftstartdate and
       shiftstarttime > shiftendtime and
       :datetime between shiftendtime and shiftstarttime
      )