Sudees
asked on
Lifo SQL Query
Hai,
I want to generate the simple LIFO based SQL query for my Purchase table:
The sample data would be in Purchase table like that:
Order No. Date Item Code Quantity Purchase Price
1 02-Aug-2012 A 97000 14.50
2 03-Aug-2012 B 12800 99.80
3 04-Aug-2012 B 27500 95.80
4 05-Aug-2012 A 45000 14.60
5 05-Aug-2012 A 55000 13.80
6 06-Aug-2012 B 45000 97.00
7 07-Aug-2012 A 11400 10.50
8 08-Aug-2012 B 11600 95.60
9 09-Aug-2012 A 12000 12.60
I want to get the purchase cost of 60000 Lots of Item A using LIFO based method, it means that lastest purchases on the basis of date will be calculated for cost so the aspected result will be:
Purchase cost of 60000 lots of item A will be 799980/-
Following is the record wise breakup of getting result of 799980/-
09-Aug-2012 105 12000 14.60
07-Aug-2012 105 11400 10.50
05-Aug-2012 105 36600 13.80
Following is the SQL script for generating Purchase table and Inserting data in it:
create table purchase (order_number number(5), order_date date,
item_code varchar2(10), Quantity number(10), Price number(8,2));
insert into purchase values ('1','02-Aug-2012','A',970 00,14.50);
insert into purchase values ('2','03-Aug-2012','B',128 00,99.80);
insert into purchase values ('3','04-Aug-2012','B',275 00,95.80);
insert into purchase values ('4','05-Aug-2012','A',450 00,14.60);
insert into purchase values ('5','05-Aug-2012','A',550 00,13.80);
insert into purchase values ('6','06-Aug-2012','B',450 00,97.00);
insert into purchase values ('7','07-Aug-2012','A',114 00,10.50);
insert into purchase values ('8','08-Aug-2012','B',116 00,95.60);
insert into purchase values ('9','09-Aug-2012','A',120 00,12.60);
Looking forward for prompt and positive feedback in this regard.
Thank you...
I want to generate the simple LIFO based SQL query for my Purchase table:
The sample data would be in Purchase table like that:
Order No. Date Item Code Quantity Purchase Price
1 02-Aug-2012 A 97000 14.50
2 03-Aug-2012 B 12800 99.80
3 04-Aug-2012 B 27500 95.80
4 05-Aug-2012 A 45000 14.60
5 05-Aug-2012 A 55000 13.80
6 06-Aug-2012 B 45000 97.00
7 07-Aug-2012 A 11400 10.50
8 08-Aug-2012 B 11600 95.60
9 09-Aug-2012 A 12000 12.60
I want to get the purchase cost of 60000 Lots of Item A using LIFO based method, it means that lastest purchases on the basis of date will be calculated for cost so the aspected result will be:
Purchase cost of 60000 lots of item A will be 799980/-
Following is the record wise breakup of getting result of 799980/-
09-Aug-2012 105 12000 14.60
07-Aug-2012 105 11400 10.50
05-Aug-2012 105 36600 13.80
Following is the SQL script for generating Purchase table and Inserting data in it:
create table purchase (order_number number(5), order_date date,
item_code varchar2(10), Quantity number(10), Price number(8,2));
insert into purchase values ('1','02-Aug-2012','A',970
insert into purchase values ('2','03-Aug-2012','B',128
insert into purchase values ('3','04-Aug-2012','B',275
insert into purchase values ('4','05-Aug-2012','A',450
insert into purchase values ('5','05-Aug-2012','A',550
insert into purchase values ('6','06-Aug-2012','B',450
insert into purchase values ('7','07-Aug-2012','A',114
insert into purchase values ('8','08-Aug-2012','B',116
insert into purchase values ('9','09-Aug-2012','A',120
Looking forward for prompt and positive feedback in this regard.
Thank you...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Sir for your quick and proper response
Great! Glad to know it helps
Let me know if you need help in understanding the query.
Let me know if you need help in understanding the query.
http://us.generation-nt.com/answer/sql-fifo-inventory-query-help-105410392.html