我工作的甲骨文11g和我想寫一個查詢,將插入11克LISTAGG功能「?」在兩個日期之間的所有缺失月份。這是我能夠實現的。 但是,現在我想整理單個記錄中特定列的所有記錄。我已經使用LISTAGG函數來實現這一點,但是我收到了LISTAGG函數內部列的錯誤「無效標識符」。 這裏是我的代碼: -甲骨文與多個子查詢
Select facilitynumber, LISTAGG(facilitystatus, '') WITHIN GROUP (ORDER BY null) "Profile" FROM ( WITH allmonths AS ( SELECT to_date(level, 'MM') AS allmnths FROM dual CONNECT BY LEVEL BETWEEN '01' AND '05' ), months AS ( SELECT * FROM ( SELECT ccds.facilitynumber,ccds.facilitystatus, dsub.filecreationdate as FacilityStatusDate, dsub.submissiondate, ROW_NUMBER() OVER (partition by ccds.facilitynumber,extract(month from dsub.submissiondate) order by dsub.submissiondate DESC) r FROM ccdssubmissions ccds INNER JOIN datasubmission dsub ON ccds.datasubmissionid = dsub.datasubmissionid INNER JOIN datasupplier dsup ON dsub.datasupplierid = dsup.datasupplierid WHERE ccds.matchedcompanynumber = 'TEST9239' ORDER BY dsub.submissiondate DESC ) where r = 1) SELECT allmnths, CASE WHEN facilitystatus IS NULL THEN '?' ELSE facilitystatus END AS "facilitystatus", submissiondate, facilitynumber FROM allmonths LEFT OUTER JOIN months ON extract(month from allmonths.allmnths) = extract(month from months.submissiondate) order by allmnths ) GROUP BY facilitynumber;
我面對錯誤在第2行本身。我的子查詢即查詢從 「WITH」 開始的返回結果如下: -
ALLMNTHS| facilitystatus | submissiondate | facilitynumber
--------- | --------------- | --------------- | ---------------
01-JAN-16 | U | 23-JAN-16 | FAC01
01-FEB-16 | ? | null | null
01-MAR-16 | 1 |05-MAR-16 | FAC01
現在使用LISTAGG(facilitystatus, ''),我想我的結果是 - >
Profile| facilitynumber
U?1 | FAC01
但,Oracle無法識別facilitystatus列,因此我無法實現預期的結果。
任何幫助將不勝感激。
謝謝
在你有外部查詢'GROUP BY facilitynumber',那就是t他的理由是你得到這個錯誤。取消組合並獲取上個月的行,它可能工作。 –
編號相同的錯誤。 – Anuja