我正在從MSSQL數據庫中獲取一個列表。我有一個數據庫表中的系統列表和材料。我想從日期範圍中獲得摘要。但數據庫給我只有不是空的行。這裏是我的代碼SQL Group by不顯示所有變量
select system_no AS 'SYSTEM NAME',
SUM(CASE WHEN (mat_2='AS') THEN mat_2_size END) as 'AS',
SUM(CASE WHEN (mat_2='SS') THEN mat_2_size END) as 'SS',
SUM(CASE WHEN (mat_2='CS') THEN mat_2_size END) as 'CS'
from fabrication_table
where welding_date between '2014-02-03' and '2014-02-09'
group by system_no
UNION
select 'TOTAL' as 'SYSTEM NAME',
SUM(CASE WHEN (mat_2='AS') THEN mat_2_size END) as 'AS',
SUM(CASE WHEN (mat_2='SS') THEN mat_2_size END) as 'SS',
SUM(CASE WHEN (mat_2='CS') THEN mat_2_size END) as 'CS'
from fabrication_table
where welding_date between '2014-02-03' and '2014-02-09'
這個查詢的結果低於
SYSTEM NAME AS SS CS
Auxiliary steam NULL NULL 6.75
Chemical dosing NULL 10.00 NULL
Closed cooling water NULL 1.50 193.75
Condensate NULL NULL 32.00
Demineralized water NULL 34.00 NULL
Feedwater NULL NULL 6.00
Gases (N2, H2, CO2) NULL NULL 385.25
GT air intake anti-icing NULL NULL 220.50
Main steam & by-pass 49.50 NULL 84.00
Seawater intake NULL 27.50 NULL
ST drains 37.50 NULL 175.50
ST seals steam NULL 2.25 175.00
TOTAL 87.00 75.25 1278.75
但我的系統名單是:
Potable water Service water Seawater intake Chemical dosing Closed cooling water GT interconnections Feedwater HRSG blowdown Sampling Fire fighting GT Lube Oil Auxiliary steam Desalted water Demineralized water ST lube & seal oil Main steam & by-pass ST drains GT air intake anti-icing Condenser vacuum ST seals steam Condensate Plant drainage Filtered water Compressed air GT drainage Fuel gas Gases (N2, H2, CO2)
這裏是我的問題:我想列出所有的變量,例如查詢沒有列出滅火,但我想列出消防這樣
Fire Fighting NULL NULL NULL
i)在表格中手動檢查「消防」,並驗證每個選擇的位置情況。 ii)刪除工會,並使用工會全部 – KumarHarsh