Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to calculate the value of inventory in sql based on the available stock buying price

Sunny86Nov 23 2018 — edited Nov 28 2018

Hello,

I am trying to calculate the inventory value based on the available stock .

For example

ProductPurchase  datequantitytotal cost
Iphone 61st Jan 20183$ 3000
Iphone 6
1st Feb 20182$2200
Iphone 61st Mar 20183$2700

ProductSale DateQuantitytotal sale price
Iphone 65th Feb 20182$4000
Iphone 6
6th Mar2$3900

Now calculating the inventory balance

select nvl(p.branch_id,s.branch_id)Branch_id,nvl(p.prod_id,s.prod_id) product_id,

       nvl(p.quantity,0) - nvl(s.quantity_sold,0) Stock_Quantity     

  from (

  select branch_id,prod_id,sum(quantity) quantity

          from costs

         group by prod_id,branch_id

       ) p

       full outer join

       (select Branch_id,prod_id,

               sum(quantity_sold) quantity_sold

from sales

         group by branch_id,prod_id

       ) s

    on p.prod_id = s.prod_id

    and p.branch_id=s.branch_id;

will give me

Total inventory balance = 4

But calculating the inventory value seems to be troublesome for me ...

1 piece at $1100 and other 3 at $900 = $3800.

Thank you very much for any helps

Comments
Post Details
Added on Nov 23 2018
24 comments
5,211 views