我整理了一个查询来列出一堆相关数据。下面是查询的简化版本以及示例输出。
SELECT DISTINCT
A.NAME AS APP_NAME,
REPLACE(H.ENVIRONMENT,',','/') AS HOST_ENVIRONMENT,
S.NAME AS SERVER_NAME,
(SELECT
LISTAGG(HS.NAME_1, '/') WITHIN GROUP(ORDER BY HS.NAME_1)
FROM
HOST_SERVER HS
WHERE
HS.NAME_2 = S.NAME
) AS HOST_NAMES,
CASE
WHEN S.LOCATION_ID IN (22,28,59) THEN 'ABC'
WHEN S.LOCATION_ID IN (6,8,9,11,53) THEN 'DBA'
WHEN S.LOCATION_ID IN (5,41,52,43,61) THEN 'ADFS'
WHEN S.LOCATION_ID IN (24,27,24,34,62,63,73) THEN 'ADR'
ELSE NULL
END AS HOST_LOCATION
FROM
APP A
FULL OUTER JOIN APP_HOST AH ON A.ID = AH.ID_1
FULL OUTER JOIN HOST H ON AH.ID_2 = H.ID
FULL OUTER JOIN HOST_SVR HS ON H.ID = HS.ID_1
FULL OUTER JOIN SVR S ON HS.ID_2 = S.ID
GROUP BY
A.NAME,
H.ENVIRONMENT,
S.NAME,
H.NAME,
S.LOCATION_ID,
S.LOCATION
ORDER BY
A.NAME
示例输出(不完整,省略了一些不重要的列):
APP_NAME HOST_ENVIRONMENT SERVER_NAME HOST_NAMES
ABCD Production server1 host1/host2/host3
ABCD Production server2 host4/host5/host6
ABCD Development server1 host1/host2/host3
ABCD UBD server2 host4/host5/host6
我想要完成的基本上是按环境对 APP_NAME 进行分组。我想要一条生产线,一条线用于其他任何东西(只是称为开发就可以了)。下面是我想要的一个例子:
APP_NAME HOST_ENVIRONMENT SERVER_NAME HOST_NAMES
ABCD Production server1/server2 host1/host2/host3/host4/host5/host6
ABCD Development server1/server2 host1/host2/host3/host4/host5/host6
如何按环境对这些应用程序进行分组?显然这是一个非常简化的版本,但我正在处理数千行。谢谢你的帮助!