SELECT
pcucode,
off_name,
COUNT(*) AS เป้าหมาย,
SUM(CASE WHEN t.mmr2="1" THEN 1 ELSE 0 END) AS MMR2,
SUM(CASE WHEN t.mmr2="1" THEN 1 ELSE 0 END) AS EPI_COVER,
SUM(CASE WHEN t.mmr2="1" THEN 1 ELSE 0 END) / COUNT(*)*100 as percen
FROM tmp_prm_vacc_3mmr2_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.mmr2="1" THEN 1 ELSE 0 END) AS MMR2,
SUM(CASE WHEN t.mmr2="1" THEN 1 ELSE 0 END) AS EPI_COVER,
SUM(CASE WHEN t.mmr2="1" THEN 1 ELSE 0 END) / COUNT(*)*100 as percen
FROM tmp_prm_vacc_3mmr2_2559 AS t
INNER JOIN co_office on off_id = pcucode