select a.itemcode,b.itemname,b.spec,b.unit,b.rprice,sum(a.rqty) rqty
from tm_possale_detail a,sys_iteminfo b
where a.itemcode=b.itemcode
group by a.itemcode,b.itemname,b.spec,b.unit,b.rprice
order by 6 desc
select a.itemcode,b.itemname,b.spec,b.unit,b.rprice,a.stockqty
from oe_branchVSstock a ,sys_iteminfo b
where a.itemcode=b.itemcode and a.itemcode in (select itemcode from sys_iteminfo where mainsupcode='81001')
SELECT a.itemcode,a.itemname,a.spec,a.unit,a.iprice,a.rprice,case when b.rqty is null then 0 else b.rqty end rqrt,a.stockqty-case when b.rqty is null then 0 else b.rqty end stockqty
FROM GYSKC('81001') a
left join nlgsale('20150728','20150730') b on a.itemcode=b.itemcode
select * from nlgsale('20150728','20150730') order by 6