select itemcode,sum(qty) as totqty,sum(totalcost) as totalcost,min(expiry) as nxtexpire from (select itemno,itemcode,expiry,qty,totalcost from items where qty > 0) a group by itemcode