SQL> desc stk; Name Type ----------------------------------------- -------- ------------------------------------ ITEM VARCHAR2(20) PRICE NUMBER(10,2) MONTH NUMBER(2) YEAR NUMBER(4) OPENING NUMBER(10) PRODUCTION NUMBER(10) SALE NUMBER(20) SQL> select * from stk; ITEM PRICE MONTH YEAR OPENING PRODUCTION SALE --------- --------- ---------- ---------- ---------- ---------- ---------- Doll 500 12 2007 100 300 375 Doll 500 11 2007 0 100 0 SQL> desc sale; Name Type ----------------------------------------------------- -------- ------------------------------------ BILL_NO NUMBER(5) BILL_DATE DATE ITEM VARCHAR2(20) PRICE NUMBER(10) QTY NUMBER(10) SQL> select * from sale; BILL_NO BILL_DATE ITEM PRICE QTY ---------- --------- -------------------- ---------- ---------- 1 10-DEC-07 Doll 300 75 2 15-DEC-07 Doll 400 125 3 17-DEC-07 Doll 300 50 4 18-DEC-07 Doll 400 75 5 18-DEC-07 Doll 300 25 6 20-DEC-07 Doll 500 25 6 rows selected. SQL> select a.item as item,a.price as price,nvl(b.opening,0) as opening, 2 nvl(b.production,0) as production,a.sale as sale, 3 ((nvl(b.opening,0)+nvl(b.production,0)-a.sale)) as closing 4 from (select item,price,sum(qty) as sale from sale 5 where bill_date between '1-dec-07' and '31-dec-07' 6 group by item,price)a, 7 (select item,price,opening,production 8 from stk where month=12 and year=2007)b 9 where a.item=b.item(+) 10 and a.price=b.price(+); ITEM PRICE OPENING PRODUCTION SALE CLOSING -------------------- ---------- ---------- ---------- ---------- ---------- Doll 300 0 0 150 -150 Doll 400 0 0 200 -200 Doll 500 100 300 25 375 Look at query result where closing is in minus figure,due to this I want to split opening and Production in such a way that it come zero and remaining opening,production and closing must come in the row which has unit price same as in stk e.g 500.