OPD
select concat(b.name,' ',strength) as drugname,generic_name,g.pharmacology_group_name,unitcost,sum(qty),units,
b.unitprice ,sum(qty*b.unitprice) as total,f.cur_dep,department
from opitemrece a
left outer join drugitems b on a.icode=b.icode
left outer join ovst f on f.vn = a.vn
left outer join kskdepartment c on f.cur_dep=c.depcode
left outer join pharmacology_group g on g.pharmacology_group_id=b.pharmacology_group1
where a.icode like'1%'
and qty>=1
and a.rxdate between '2016-03-10' and '2016-03-12' and a.an is null
group by b.name,strength,units,b.unitprice,a.dep_code,department
order by f.cur_dep,b.name
IPD
select concat(b.name,' ',strength) as drugname,generic_name,g.pharmacology_group_name,unitcost,sum(qty),units,
b.unitprice ,sum(qty*b.unitprice) as total,f.cur_dep,department
from opitemrece a
left outer join drugitems b on a.icode=b.icode
left outer join ovst f on f.vn = a.vn
left outer join kskdepartment c on f.cur_dep=c.depcode
left outer join pharmacology_group g on g.pharmacology_group_id=b.pharmacology_group1
where a.icode like'1%'
and qty>=1
and a.rxdate between '2016-03-10' and '2016-03-12' and a.an<>""
group by b.icode
order by f.cur_dep,b.name