Oracle SQL - Combine two select statements -


select qi.qtyonhand + qd.delqty teste,        qi.itemname   qitem qi, qdel qd  qi.itemname = qd.itemname    , qd.deptname = 'recreation';   select qi.qtyonhand - qs.saleqty teste,        qi.itemname   qsale qs, qitem qi  qi.itemname = qs.itemname    , qs.deptname = 'recreation'; 

i'm trying update qitem quantity count adding qdel table's quantity , subtracting qsale table's quantity. i'm trying put 1 column, there may not items in qdel table department name of "recreation" when try put select statements one, leaves out items qitems.

how this? if not give desired result, can show sample data better explain need?

select qi.qtyonhand + nvl(qd.delqty,0) + nvl(qa.saleqty,0)  teste, qi.itemname qitem qi left outer join (select * qdel deptname = 'recreation') qd   on qi.itemname = qd.itemname left outer join (select * qsale deptname = 'recreation') qs   on qi.itemname = qs.itemname (qd.delqty not null or qs.saleqty not null) 

(there may simpler way it, if qitem has deptname column.)


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -