SELECT person.hospcode,
chospcode.hospname,
COUNT(DISTINCT l.CID) as target
FROM tmp_labor6700 l
INNER JOIN person on person.CID = l.cid
INNER JOIN chospcode on chospcode.hospcode = person.hospcode
WHERE
l.BDATE BETWEEN "2016-04-01" and "2017-03-31"
and person.TYPEAREA in ("1","3") and person.DISCHARGE ="9"
and l.BHOSP="10727" and l.HOSPCODE="10727"
GROUP BY person.HOSPCODE
UNION
select "รวมทั้งคัพ" as hoscode,"" as hosname
,count(*) target
FROM tmp_labor6700 l
INNER JOIN person on person.CID = l.cid
INNER JOIN chospcode on chospcode.hospcode = person.hospcode
WHERE
l.BDATE BETWEEN "2016-04-01" and "2017-03-31"
and person.TYPEAREA in ("1","3") and person.DISCHARGE ="9"
and l.BHOSP="10727" and l.HOSPCODE="10727"