SELECT
pcucode,
off_name,
COUNT(*) AS เป้าหมาย,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) AS MMR,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) AS EPI_COVER,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) / COUNT(*)*100 as percen
FROM tmp_prm_vacc_1mmr_2559 AS t
INNER JOIN co_office on off_id = pcucode
GROUP BY pcucode
union
select "ภาพรวมทั้งคัพ" as pcucode,"" as off_name,
COUNT(*) AS เป้าหมาย,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) AS MMR,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) AS EPI_COVER,
SUM(CASE WHEN t.mmr="1" THEN 1 ELSE 0 END) / COUNT(*)*100 as percen
FROM tmp_prm_vacc_1mmr_2559 AS t
INNER JOIN co_office on off_id = pcucode