Reputation: 478
I know how to count
or take sum
but my question is different.
Above is my count list. I want to add up my all 3 column counts like 7+68+13....= sum
SELECT COUNT(DISTINCT od.`meter_serial`) AS 'OGP Created',
COUNT(DISTINCT mp.`meter_id`) AS 'Installed & Un-Verified Meters',
COUNT(DISTINCT ins.`meter_msn`) AS 'Installed & Verified',
sd.`sub_div_code` AS 'SD Code',sd.`name` AS 'SD-Name'
FROM `ogp_detail` od
INNER JOIN `survey_hesco_subdivision` sd ON od.`sub_div` = sd.`sub_div_code`
LEFT JOIN `meter_ping` mp ON od.`meter_id` = mp.`meter_id`
LEFT JOIN `installations` ins ON od.`meter_serial` = ins.`meter_msn`
WHERE od.`meter_type` = '3-Phase'
GROUP BY sd.`name`
I want the sum of counts to be shown below each of the 3
columns while displaying count as-well.
Any help would be highly appreciated.
Upvotes: 0
Views: 50
Reputation: 94894
Either simply add the expression
COUNT(DISTINCT od.meter_serial) +
COUNT(DISTINCT mp.meter_id) +
COUNT(DISTINCT ins.meter_msn) AS total
Or make your query a subquery:
select
"OGP Created",
"Installed & Un-Verified Meters",
"Installed & Verified",
"OGP Created" + "Installed & Un-Verified Meters" + "Installed & Verified" as total
from ( your query here ) q;
Upvotes: 1