select drugname,count(distinct visit.pcucode,visit.pid) as 'คน' ,
count(visitdrug.unit) as 'ครั้ง'
from visit
left join visitdrug on visit.visitno = visitdrug.visitno and visit.pcucode = visitdrug.pcucode    left join cdrug on visitdrug.drugcode = cdrug.drugcode
where cdrug.drugtype='02' and cdrug.drugtypesub = '4' and visit.visitdate between  '2014-10-01' and '2015-09-30'
group by cdrug.drugcode;