select drugname,count(distinct visit.pcucode,visit.pid) as 'คน' ,
count(visitdrug.unit) as 'ครั้ง'
from visit 
INNER JOIN visitdrug on visit.visitno = visitdrug.visitno and visit.pcucode = visitdrug.pcucode
INNER JOIN cdrug on visitdrug.drugcode = cdrug.drugcode
where cdrug.drugtype='02' 
and cdrug.drugtypesub = '3' 
and visit.visitdate between '2013-07-01' and '2014-10-31'
group by cdrug.drugcode;