我已經編輯我的查詢象下面這樣:在發生需要幫助值
SELECT
ser.SERVER_COMPONENT_NAME, ITServ.IT_SERVICE_BUSINESS_CRITICALIT,
app.APPCROWNJEWEL,
MAX(CASE
WHEN ITServ.IT_SERVICE_BUSINESS_CRITICALIT = 'Tier o' THEN 1
WHEN ITServ.IT_SERVICE_BUSINESS_CRITICALIT = 'Tier 1' THEN 3
WHEN ITServ.IT_SERVICE_BUSINESS_CRITICALIT = 'Tier 2' THEN 5
WHEN ITServ.IT_SERVICE_BUSINESS_CRITICALIT IS NULL THEN 5
ELSE 0
END) AS TierRatingValue,
MAX(CASE
WHEN app.APPCROWNJEWEL = 'Yes' THEN 3
WHEN app.APPCROWNJEWEL = 'No' THEN 2
ELSE 1
END) AS JewelsValue
FROM
TDM_FACT_SERVER ser
LEFT JOIN
TDM_RKT_SM_TO_SERVER smServer ON smServer.SERVER_COMPONENT_ID = Ser.SERVER_COMPONENT_ID
AND smServer.SOFTWARE_MODULE_COMPONENT_ID IN (SELECT DISTINCT sm.SOFTWARE_MODULE_COMPONENT_ID
FROM software_module sm
WHERE sm.SOFTWARE_MODULE_COMPONENT_NAME LIKE 'DBSM:%' OR
sm.SOFTWARE_MODULE_COMPONENT_NAME LIKE 'MWSM:%' OR
sm.SOFTWARE_MODULE_COMPONENT_NAME like 'CMS:%')
LEFT JOIN
SOFTWARE_MODULE sm ON sm.SOFTWARE_MODULE_COMPONENT_ID = smServer.SOFTWARE_MODULE_COMPONENT_ID
LEFT JOIN
TDM_RKT_IT_SERVICE_TO_SM ITSERVICETOSM ON sm.SOFTWARE_MODULE_COMPONENT_ID = ITSERVICETOSM.SOFTWARE_MODULE_COMPONENT_ID
AND ITSERVICETOSM.IT_SERVICE_COMPONENT_ID IN (SELECT DISTINCT Itserv.IT_SERVICE_COMPONENT_ID
FROM tdm_fact_it_srvc Itserv
WHERE Itserv.IT_SERVICE_SERVICE_RECONCILIAT IN ('Active in PLADA but not present in GSD',
'Active in GSD but not present in PLADA',
'Active in GSD and PLADA',
'Active in GSD but demised in PLADA',
'Active in PLADA but demised in GSD'))
LEFT JOIN
TDM_FACT_IT_SRVC ITServ ON ITSERVICETOSM.IT_SERVICE_COMPONENT_ID = ITServ.IT_SERVICE_COMPONENT_ID
LEFT JOIN
TDM_RKT_APP_TO_ITSERVICE ApptoITService ON ITServ.IT_SERVICE_COMPONENT_ID = ApptoITService.IT_SERVICE_COMPONENT_ID
LEFT JOIN
hsbc_ci_inventory_as app ON ApptoITService.APPLICATION_COMPONENT_ID = app.appid
WHERE
ser.SERVER_COMPONENT_NAME = 'GBL03427'
GROUP BY
ser.SERVER_COMPONENT_NAME, ITServ.IT_SERVICE_BUSINESS_CRITICALIT,
app.APPCROWNJEWEL
下面是輸出,因爲它是產生兩個新列如預期。
Server TierRating Jewels TierRatingValue JewelsValue
--------- ---------- ---------- ---------------- -----------
GBL03427 Tier 0 No 0 2
GBL03427 Tier 1 Yes 3 3
GBL03427 Tier 2 Undefined 5 1
GBL03427 Tier 1 No 3 2
GBL03427 Tier 2 No 5 2
GBL03427 Tier 0 Yes 0 3
GBL03427 Tier 1 NULL 3 1
GBL03427 NULL NULL 5 1
GBL03427 Tier 1 Undefined 3 1
GBL03427 Tier 0 Undefined 0 1
但我希望看到輸出爲一行,最大值爲TierRatingValue和JewelsValue,如下所示。
Server TierRating Jewels TierRatingValue JewelsValue
--------- ---------- ---------- ---------------- -----------
GBL03427 Tier 2 Yes 5 3
請標記您正在使用的正確數據庫。MySQL,SQL-server和SQLite是不一樣的。 –
如果您要提供樣本數據(例如插入語句或使用with子句),這也會有所幫助。你有沒有嘗試過「Group By」 - 激情?例如。選擇...按TierRating分組。 – Benjamin
歡迎使用StackOverflow:如果您發佈代碼,XML或數據示例,請***在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕(「{}」)格式和語法突出顯示它! –