Oracle SQL:填写日期之间的日期

时间:2015-10-07 09:16:01

标签: sql oracle

我有以下基本脚本,这显示了我的生产计划中的一些当前容量加载。

select rl.duedate, rl.reservation_no resnr, qty
from gps_reservation_load rl
where rl.reservation_no in ('179459','179460','179461')
and rl.work_center_no in ('ALIN','AVD5','AVD9')

enter image description here

但是,我想将DUEDATE显示为从sysdate到年末的日期范围,例如

enter image description here

我有以下内容给了我这个范围但是,如何组合脚本给我上面的结果?

select trunc(sysdate + rownum) dt
from DUAL connect by rownum < (to_date('01-JAN-2016', 'dd-mon-yyyy') - trunc(sysdate))

1 个答案:

答案 0 :(得分:1)

您只需要使用外连接。

SELECT duedate_generated,reservation_no, qty,  dt
from 
(SELECT 
    trunc(sysdate + rownum) AS duedate_generated
 FROM  DUAL
 connect by rownum < (to_date('01-JAN-2016', 'dd-mon-yyyy') - trunc(sydsate)
) d
OUTER JOIN 
(select
   duedate, reservation_no resnr, qty
 from gps_reservation_load
 where 
     reservation_no in ('179459','179460','179461')
 and work_center_no in ('ALIN','AVD5','AVD9')
) r1
ON (d.duedate_generated = r1. due date)