如何在列表agg中的连接列上执行distinct

时间:2018-02-20 16:22:34

标签: oracle listagg

这是我想要在listagg上做的不同的查询。此列未被选中t2.comms_matrix_id

SELECT *
FROM ccp.v_comms_matrix_data vcmd
LEFT JOIN (
    SELECT t1.service_id
        ,t1.src
        ,t1.dst
        ,t1.protocol
        ,t1.ports
        ,t1.duplicates
        ,LISTAGG(t2.comms_matrix_id, ', ' ) WITHIN
    GROUP (
            ORDER BY t2.comms_matrix_id
            ) CMIDS
    FROM (
        SELECT s1.service_id
            ,s2.src
            ,s2.dst
            ,s2.protocol
            ,s2.ports
            ,COUNT(*) DUPLICATES
        FROM CCP.comms_matrices s1
        INNER JOIN CCP.comms_matrix_data s2 ON (s1.id = s2.comms_matrix_id)

        GROUP BY s1.service_id
            ,s2.src
            ,s2.dst
            ,s2.protocol
            ,s2.ports
        HAVING COUNT(*) > 10
        ) t1
    INNER JOIN CCP.comms_matrix_data t2 ON (t1.src = t2.src)
        AND (t1.dst = t2.dst)
        AND (t1.protocol = t2.protocol)
        AND (t1.ports = t2.ports)
    INNER JOIN ccp.comms_matrices t3 ON t2.comms_matrix_id = t3.id
        AND t1.service_id = t3.service_id

    GROUP BY t1.service_id
        ,t1.src
        ,t1.dst
        ,t1.protocol
        ,t1.ports
        ,t1.duplicates
    ) dupes ON dupes.src = vcmd.src
    AND dupes.dst = vcmd.dst
    AND dupes.protocol = vcmd.protocol
    AND dupes.ports = vcmd.ports;

它给了我错误OCI_ERROR: 1489

示例数据

SERVICE_ID  SERVICE_REF SERVICE OWNER   FROZEN  ID  COMMS_MATRIX_ID FILENAME    CMLINE  SRC SRC_NET SRC_ZONE    SRC_SECZONE SRC_NETZONE DST DST_NET DST_ZONE    DST_SECZONE DST_NETZONE SPA SPN RPA RPN STATUS  PROTOCOL    PORTS   REMARKS DROW    SRC_DESC    DST_DESC    ENVIRONMENT CREATED_BY  UPDATED_BY  TS_CREATED  FPA FPN SRC_LOCZONE DST_LOCZONE ECT TRACK   SERVICE_GROUPING    DUPLICATES  CMIDS
3       * Ad-hoc Submission UddinS2 0   3486259 16606   failing.xlsx    9   198.168.1.1/26  198.168.1.1/26  G   U   CC  198.168.2.1/26  198.168.2.1/26  G   U   CC  Prevention  Prevention #6407.112346 - Declined by UddinS2 until Forever (Note: flow id #3486259)    Permit  Flow is permitted within the same routing domain    To implement    TCP 1521    OSM TEST/DEV AS -> UIM DEV DB   11  IPBB - CC   IPBB - CC   TEST    wwwadm  UddinS2 27-FEB-18 19.34.00.567918000    Permit  Flow is permitted using an acceptable port  MIL MIL None    1       4   16202, 16202, 16606, 16606
3       * Ad-hoc Submission UddinS2 0   3486259 16606   failing.xlsx    9   198.168.1.1/26  198.168.1.1/26  G   U   CC  198.168.2.1/26  198.168.2.1/26  G   U   CC  Prevention  Prevention #6407.112346 - Declined by UddinS2 until Forever (Note: flow id #3486259)    Permit  Flow is permitted within the same routing domain    To implement    TCP 1521    OSM TEST/DEV AS -> UIM DEV DB   11  IPBB - CC   IPBB - CC   TEST    wwwadm  UddinS2 27-FEB-18 19.34.00.567918000    Permit  Flow is permitted using an acceptable port  MIL MIL None    1       2   16180, 16180

最后两列应该合并,它不应该显示为2个单独的行,这是没有意义的

0 个答案:

没有答案