我試圖使用LEFT JOIN連接3個表,但我總是有錯誤。請幫幫我。在3個表中使用左連接
謝謝
,我想輸出:
Name Date Open Close
POS 01/01/2014 4 10
ONE 01/02/2014 6 5
...
...
...
我的查詢:
SELECT 'Data'
||','||TO_CHAR(D.DTIME_DAY,'MM/dd/yyyy')
||','||NVL(o.CNT_OPENED,0) --as cnt_opened
||','||NVL(c.CNT_CLOSED,0) --as cnt_closed
||','||q.NAME
FROM OWNER_DWH.DC_DATE d
LEFT JOIN APP_ACCOUNT.OTRS_QUEUE q
ON t.queue_id = q.id
LEFT JOIN (
SELECT TRUNC(t.CREATE_TIME) AS report_date,count(*) AS cnt_opened
FROM APP_ACCOUNT.OTRS_TICKET t
WHERE t.CREATE_TIME BETWEEN SYSDATE -120 AND SYSDATE
GROUP BY TRUNC(t.CREATE_TIME)
) o ON d.DTIME_DAY=o.REPORT_DATE
LEFT JOIN (
SELECT TRUNC(t.CLOSE_TIME) as report_date,count(*) AS cnt_closed
FROM APP_ACCOUNT.OTRS_TICKET t
WHERE t.CLOSE_TIME BETWEEN SYSDATE -120 AND SYSDATE
GROUP BY TRUNC(t.CLOSE_TIME)
) c ON D.DTIME_DAY=c.REPORT_DATE
WHERE d.DTIME_DAY BETWEEN SYSDATE -120 AND TRUNC(SYSDATE) -1
AND d.DTIME_DAY = TRUNC(d.DTIME_DAY)
AND TRUNC(d.DTIME_DAY)= d.DTIME_DAY
ORDER BY D.DTIME_DAY;
刪除第8行中的';'然後嘗試'ON t.queue_id = q.id' – Dba
任何含錯誤的語言? – wruckie
ORA-00904:「T」。「QUEUE_ID」:無效標識符@wruckie – user3098728