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!

Tricky query finding Stock balance age days

Arif2018Jun 21 2018 — edited Jun 23 2018

I have a tricky situation , to know the stock balance based on receipt date on following criteria s -

1.Stock days to calculate from the first receipt date till next receipt date

2.Stock days to consider only receipt if there are no issuances.

item A--- STOCK BALANCE R-I (10- 3 + 5 = 12)

item  B---STOCK BALANCE R-I (5-0 =5 )

item C ---  STOCK BALANCE R-I (5-1-4 =1)

item D--- STOCK BALANCE R-I (5-1=4)

[code]

create table stk_trans(stk_date date,stk_item varchar2(12),stk_qty number,stk_r_i varchar2(1))

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/01/2018','DD/MM/YYYY'),'A',10,'R')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/03/2018','DD/MM/YYYY'),'A',2,'I')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/04/2018','DD/MM/YYYY'),'A',1,'I')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/06/2018','DD/MM/YYYY'),'A',5,'R') 

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/01/2018','DD/MM/YYYY'),'B',5,'R')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/04/2018','DD/MM/YYYY'),'C',5,'R')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/05/2018','DD/MM/YYYY'),'C',1,'I')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/05/2018','DD/MM/YYYY'),'C',4,'I')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('01/06/2018','DD/MM/YYYY'),'D',5,'R')

insert into stk_trans (stk_date ,stk_item ,stk_qty, stk_r_i) values (TO_DATE('25/06/2018','DD/MM/YYYY'),'D',1,'I')

--Need out put as below...

item        0-90    91-180   181-270  >270

A                5                                       7    

B                                                         5    

C                1                                           

D                4                                            

[/code]

This post has been answered by mNem on Jun 22 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 21 2018
Added on Jun 21 2018
20 comments
529 views