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