select pid,visit.visitno,visitdate ,cdrug.drugname,visitdrug.unit,costprice,realprice from visit
INNER JOIN visitdrug on visit.visitno = visitdrug.visitno
INNER JOIN cdrug on visitdrug.drugcode = cdrug.drugcode and cdrug.drugtype = 02

where visitdate BETWEEN '20140701' and '20150930' and (costprice = 0 or realprice = 0)
order by visitdate;