SELECT person.hospcode,
chospcode.hospname,
COUNT(DISTINCT l.CID) as target
FROM tmp_labor6700_2559 l
INNER JOIN person on person.CID = l.cid
INNER JOIN chospcode on chospcode.hospcode = person.hospcode
WHERE
l.BDATE BETWEEN "2015-10-01" and "2016-09-30"
and person.TYPEAREA in ("1","3") and person.DISCHARGE ="9"
and l.BHOSP in ("10727","11272","11268","11266","00000") and l.HOSPCODE in ("10727","11272","11268","11266")
GROUP BY person.HOSPCODE
UNION
select "รวมทั้งคัพ" as hoscode,"" as hosname
,count(*) target
FROM tmp_labor6700_2559 l
INNER JOIN person on person.CID = l.cid
INNER JOIN chospcode on chospcode.hospcode = person.hospcode
WHERE
l.BDATE BETWEEN "2015-10-01" and "2016-09-30"
and person.TYPEAREA in ("1","3") and person.DISCHARGE ="9"
and l.BHOSP in ("10727","11272","11268","11266","00000") and l.HOSPCODE in ("10727","11272","11268","11266")