SELECT d.HOSPCODE,m.HOSPNAME
,count(case when d.DATE_SERV BETWEEN '".$strKeyword."' and '".$strKeyword2."' then 1 else null end ) as service_all
FROM f43_diagnosis_op d
LEFT JOIN mas_client m ON d.HOSPCODE = m.HOSPCODE
WHERE d.DELETE_FLAG = '0' AND d.DIAGTYPE = 1
AND d.DIAGCODE NOT LIKE 'Z1%' AND d.DIAGCODE NOT LIKE 'Z0%' AND d.DIAGCODE NOT LIKE 'Z7%'
GROUP BY d.HOSPCODE
Code (PHP)
SELECT d.HOSPCODE,m.HOSPNAME
,count(case when d.DATE_SERV BETWEEN '20161001' and '20170930' then 1 else null end ) as service_all
FROM f43_diagnosis_op d
LEFT JOIN mas_client m ON d.HOSPCODE = m.HOSPCODE
WHERE d.DELETE_FLAG = '0' AND d.DIAGTYPE = 1
AND d.DIAGCODE NOT LIKE 'Z1%' AND d.DIAGCODE NOT LIKE 'Z0%' AND d.DIAGCODE NOT LIKE 'Z7%'
GROUP BY d.HOSPCODE