Dynamically calculate number of days between two dates and split amounts
VladKApr 26 2010 — edited Apr 27 2010Hello,
I have been searching for a solution for this, but didn't have any success.
I need to show amounts split by days.
I have a table that has an amount column, and start and end dates.
I need to write a query in such a way that the amounts will be broken up evenly based on the number of days between start date and end date.
For example, for this row,
insert into my_test values (1, '3-mar-2010', '7-mar-2010', 1000);
the query would return this (splitting $1,000 across 5 days)
ID Date Amount
1 '3-mar-2010' 200.00
1 '4-mar-2010' 200.00
1 '5-mar-2010' 200.00
1 '6-mar-2010' 200.00
1 '7-mar-2010' 200.00
create table my_test (
id number(10),
start_date date,
end_date date,
amount number(10,2)
);
select * from my_test
insert into my_test values (1, '3-mar-2010', '7-mar-2010', 1000);
insert into my_test values (2, '10-mar-2010', '19-mar-2010', 2000);
insert into my_test values (3, '20-mar-2010', '21-mar-2010', 5000);
Thanks in advance.