以下のクエリが 2 つの集計関数 (合計) の差を適切に取得しないのはなぜですか?
SELECT
epa.status as Status,
sum(equip_port_usage.total_nbr_ports) as Total,
sum(equip_port_usage.NBR_PORTS_ASSIGNED) as Used,
sum(equip_port_usage.NBR_PORTS_ASSIGNED)
- sum(equip_port_usage.NBR_PORTS_ASSIGNED) as Difference
FROM site_inst
INNER JOIN site_attr_settings
ON site_attr_settings.site_inst_id = site_inst.site_inst_id
INNER JOIN epa on epa.site_inst_id=site_inst.site_inst_id
INNER JOIN equip_inst ON equip_inst.site_inst_id=site_inst.site_inst_id
INNER JOIN equip_port_usage
ON equip_port_usage.equip_inst_id=equip_inst.equip_inst_id
WHERE site_inst.SITE_HUM_ID = 'CLEUS'
GROUP BY epa.status;
出力は以下のようになります
Ok 303876 10276 0
Faulty 19044 644 0
Reserved 19872 672 0
私はそれを期待しています
Ok 303876 10276 293600
Faulty 19044 644 18400
Reserved 19872 672 19200