我在SQL脚本中创建日期范围时遇到了问题。
我创建了一个日期范围表('dt'表),它作为一个独立的脚本运行OK但是,当添加到下面的脚本时,它只显示trunc(rl.daudate)= dt.dateval的日期。我需要dt.dateval显示即使没有匹配到trunc(rl.duedate)
select dt.dateval, rl.reservation_no, gr.title, gr.catnr, rl.duedate, rl.work_center_no, rl.tec_criteria, rl.qty
from gps_reservation gr, GPS_RESERVATION_LOAD rl,
(select x.dateval from
(select (trunc(sysdate+90) - rownum) -1 dateval from dual
connect by rownum < (1*90) ) x ) dt
where rl.reservation_no = gr.reservation_no
and rl.plant = 'W'
and gr.active_flag = 'Y'
and gr.cap_flag = 'Y'
and trunc(rl.duedate) = dt.dateval
我通常会使用(+)联接,即
and trunc(rl.duedate) (+) = dt.dateval
...但是,我收到'ORA-00936:缺少表达式:-936'错误?
有什么想法吗? 非常感谢
答案 0 :(得分:2)
试试这个:
SELECT
dt.dateval
, rl.reservation_no
, gr.title
, gr.catnr
, rl.duedate
, rl.work_center_no
, rl.tec_criteria
, rl.qty
FROM (
SELECT (trunc(sysdate + 90) - rownum) - 1 dateval
FROM dual connect BY rownum < (1 * 90)
) dt
LEFT JOIN GPS_RESERVATION_LOAD rl ON dt.dateval = trunc(rl.duedate)
AND rl.plant = 'W'
LEFT JOIN gps_reservation gr ON rl.reservation_no = gr.reservation_no
AND gr.active_flag = 'Y'
AND gr.cap_flag = 'Y'