select i.name ,count(distinct o.hn) as hn_d_count,count(o.icode) as i_count ,sum(o.qty*o.unitprice) as price
from ipt_oper_code i
left outer join opitemrece o on o.icode=i.icode and o.rxdate between "2005-08-01" and "2005-08-30" and o.an is not null
group by i.name
having count(o.icode)>0
order by i.name