我希望收到来自c源的最后一个值为MODLOGIN
的列,但我仍然收到错误:
ORA-00933命令未正确结束。
WITH a AS (SELECT
a.UIDINSTANCEID, a.APPLICATIONNUMBER,a.FIELD3,a.APPLICATIONDATE,a.FIELD12,a.FIELD6 , a.FIELD9, a.FIELD16, a.APPLICATIONSTATUSSYMBOL
FROM HDD99_DSA_UNU.V_APPLICATION a
WHERE
(a.field6 = 'ZAJECIA_EGZEKUCYJNE' or a.field9 = 'ZAJECIA_EGZEKUCYJNE')
AND a.field12 >= :DATA_ROZWIAZANIA_START AND a.field12 <= :DATA_ROZWIAZANIA_KONIEC AND a.HDB_LAST = 'Y'),
c AS (SELECT c.UIDINSTANCEID,c.NEWSTATUSSYMBOL,c.MODDATE,c.MODLOGIN
FROM HDD99_DSA_UNU.V_APPLICATIONEVENTLOG_1R c
),
h AS (SELECT DISTINCT SYMBOL, MAX(NAME) AS NAME FROM
(SELECT h.SYMBOL,h.NAME FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h WHERE h.DICTID = 839 AND h.HDB_LAST = 'Y'
UNION ALL
SELECT h.SYMBOL,h.NAME FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h WHERE h.DICTID = 1226 AND h.HDB_LAST = 'Y'
UNION ALL
SELECT h.SYMBOL,h.NAME FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h WHERE h.DICTID = 1285 AND h.HDB_LAST = 'Y')
GROUP BY SYMBOL)
SELECT
a.APPLICATIONNUMBER AS NR,
to_number(LPAD(a.FIELD3,3)) AS TECHNICZNY_NR,
h.NAME AS NAZWA_DYSPOZYCJI,
TO_CHAR(TO_TIMESTAMP(a.APPLICATIONDATE),'YYYY-MM-DD HH24:MI:SS') AS DATA_REJESTRACJI,
TO_CHAR(TO_TIMESTAMP(a.FIELD12),'YYYY-MM-DD HH24:MI:SS') as DATA_ROZWIAZANIA,
a.FIELD6 AS GRUPA,
a.FIELD9 AS GRUPA2,
a.APPLICATIONSTATUSSYMBOL,
a.FIELD16 AS SLA,
MAX(c.MODLOGIN) KEEP (DENSE_RANK LAST ORDER BY c.UIDINSTANCEID,c.MODDATE) as MODLOGIN
FROM HDD99_DSA_UNO.V_APPLICATION a
GROUP BY c.UIDINSTANCEID
LEFT JOIN HDD99_DSA_UNO.V_APPLICATIONEVENTLOG c
ON a.UIDINSTANCEID = c.UIDINSTANCEID
LEFT JOIN h ON LPAD(a.FIELD3,3) = h.SYMBOL
答案 0 :(得分:0)
您需要JOIN
之前的GROUP BY
。
WITH a AS (SELECT a.UIDINSTANCEID, a.APPLICATIONNUMBER, a.FIELD3, a.APPLICATIONDATE, a.FIELD12, a.FIELD6, a.FIELD9, a.FIELD16, a.APPLICATIONSTATUSSYMBOL
FROM HDD99_DSA_UNU.V_APPLICATION a
WHERE (a.field6 = 'ZAJECIA_EGZEKUCYJNE' OR a.field9 = 'ZAJECIA_EGZEKUCYJNE')
AND a.field12 BETWEEN :DATA_ROZWIAZANIA_START AND :DATA_ROZWIAZANIA_KONIEC
AND a.HDB_LAST = 'Y'),
c AS (SELECT c.UIDINSTANCEID, c.NEWSTATUSSYMBOL, c.MODDATE, c.MODLOGIN
FROM HDD99_DSA_UNU.V_APPLICATIONEVENTLOG_1R c),
h AS (SELECT DISTINCT SYMBOL, MAX(NAME) AS NAME
FROM (SELECT h.SYMBOL, h.NAME
FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h
WHERE h.DICTID = 839
AND h.HDB_LAST = 'Y'
UNION ALL
SELECT h.SYMBOL, h.NAME
FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h
WHERE h.DICTID = 1226
AND h.HDB_LAST = 'Y'
UNION ALL
SELECT h.SYMBOL, h.NAME
FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h
WHERE h.DICTID = 1285
AND h.HDB_LAST = 'Y')
GROUP BY SYMBOL)
SELECT a.APPLICATIONNUMBER AS NR,
to_number(LPAD(a.FIELD3,3)) AS TECHNICZNY_NR,
h.NAME AS NAZWA_DYSPOZYCJI,
TO_CHAR(TO_TIMESTAMP(a.APPLICATIONDATE),'YYYY-MM-DD HH24:MI:SS') AS DATA_REJESTRACJI,
TO_CHAR(TO_TIMESTAMP(a.FIELD12),'YYYY-MM-DD HH24:MI:SS') AS DATA_ROZWIAZANIA,
a.FIELD6 AS GRUPA,
a.FIELD9 AS GRUPA2,
a.APPLICATIONSTATUSSYMBOL,
a.FIELD16 AS SLA,
MAX(c.MODLOGIN) KEEP (DENSE_RANK LAST ORDER BY c.UIDINSTANCEID,c.MODDATE) AS MODLOGIN
FROM HDD99_DSA_UNO.V_APPLICATION a
LEFT JOIN HDD99_DSA_UNO.V_APPLICATIONEVENTLOG c ON a.UIDINSTANCEID = c.UIDINSTANCEID
LEFT JOIN h ON LPAD(a.FIELD3,3) = h.SYMBOL
GROUP BY c.UIDINSTANCEID, a.APPLICATIONNUMBER, to_number(LPAD(a.FIELD3,3)), h.NAME, TO_CHAR(TO_TIMESTAMP(a.APPLICATIONDATE),'YYYY-MM-DD HH24:MI:SS'), TO_CHAR(TO_TIMESTAMP(a.FIELD12),'YYYY-MM-DD HH24:MI:SS'), a.FIELD6, a.FIELD9, a.APPLICATIONSTATUSSYMBOL, a.FIELD16
这也可能有助于消除对UNION ALL
的需求。
WITH a AS (SELECT a.UIDINSTANCEID, a.APPLICATIONNUMBER, a.FIELD3, a.APPLICATIONDATE, a.FIELD12, a.FIELD6, a.FIELD9, a.FIELD16, a.APPLICATIONSTATUSSYMBOL
FROM HDD99_DSA_UNU.V_APPLICATION a
WHERE (a.field6 = 'ZAJECIA_EGZEKUCYJNE' OR a.field9 = 'ZAJECIA_EGZEKUCYJNE')
AND a.field12 BETWEEN :DATA_ROZWIAZANIA_START AND :DATA_ROZWIAZANIA_KONIEC
AND a.HDB_LAST = 'Y'),
c AS (SELECT c.UIDINSTANCEID, c.NEWSTATUSSYMBOL, c.MODDATE, c.MODLOGIN
FROM HDD99_DSA_UNU.V_APPLICATIONEVENTLOG_1R c),
h AS (SELECT DISTINCT SYMBOL, MAX(NAME) AS NAME
FROM (SELECT h.SYMBOL, h.NAME
FROM HDD99_DSA_UNU.V_DICTIONARYVALUES h
WHERE h.DICTID IN (839, 1226, 1285)
AND h.HDB_LAST = 'Y')
GROUP BY SYMBOL)
SELECT a.APPLICATIONNUMBER AS NR,
to_number(LPAD(a.FIELD3,3)) AS TECHNICZNY_NR,
h.NAME AS NAZWA_DYSPOZYCJI,
TO_CHAR(TO_TIMESTAMP(a.APPLICATIONDATE),'YYYY-MM-DD HH24:MI:SS') AS DATA_REJESTRACJI,
TO_CHAR(TO_TIMESTAMP(a.FIELD12),'YYYY-MM-DD HH24:MI:SS') AS DATA_ROZWIAZANIA,
a.FIELD6 AS GRUPA,
a.FIELD9 AS GRUPA2,
a.APPLICATIONSTATUSSYMBOL,
a.FIELD16 AS SLA,
MAX(c.MODLOGIN) KEEP (DENSE_RANK LAST ORDER BY c.UIDINSTANCEID,c.MODDATE) AS MODLOGIN
FROM HDD99_DSA_UNO.V_APPLICATION a
LEFT JOIN HDD99_DSA_UNO.V_APPLICATIONEVENTLOG c ON a.UIDINSTANCEID = c.UIDINSTANCEID
LEFT JOIN h ON LPAD(a.FIELD3,3) = h.SYMBOL
GROUP BY c.UIDINSTANCEID, a.APPLICATIONNUMBER, to_number(LPAD(a.FIELD3,3)), h.NAME, TO_CHAR(TO_TIMESTAMP(a.APPLICATIONDATE),'YYYY-MM-DD HH24:MI:SS'), TO_CHAR(TO_TIMESTAMP(a.FIELD12),'YYYY-MM-DD HH24:MI:SS'), a.FIELD6, a.FIELD9, a.APPLICATIONSTATUSSYMBOL, a.FIELD16