SELECT HOSPCODE
,count(case when BIRTH BETWEEN '20150905' and '20151008' then 1 else null end ) as 9m
,count(case when BIRTH BETWEEN '20141205' and '20150108' then 1 else null end ) as 18m
FROM f43_person
WHERE NATION = '099'
and DISCHARGE = '9'
AND TYPEAREA in (1,3)
GROUP BY HOSPCODE
2. Code (PHP)
SELECT a.HOSPCODE,COUNT(DISTINCT a.CID) as จำนวน9รักษา
FROM f43_person a
INNER JOIN f43_specialpp b ON a.CID = b.CID and a.TYPEAREA in (1,3) AND BIRTH BETWEEN '20141205' and '20150108'
WHERE b.DATE_SERV BETWEEN '20160704' AND '20160708'
AND b.PPSPECIAL like '1b2%'
AND a.NATION = '099'
and a.DISCHARGE = '9'
GROUP BY a.HOSPCODE
3. Code (PHP)
SELECT a.HOSPCODE,COUNT(DISTINCT a.CID) as จำนวน18รักษา
FROM f43_person a
INNER JOIN f43_specialpp b ON a.CID = b.CID and a.TYPEAREA in (1,3) AND BIRTH BETWEEN '20131205' and '20140108'
WHERE b.DATE_SERV BETWEEN '20160704' AND '20160708'
AND b.PPSPECIAL like '1b2%'
AND a.NATION = '099'
and a.DISCHARGE = '9'
GROUP BY a.HOSPCODE