+-------+-----------+------+----------------------+----------------------+
|RATE_ID|DESCRIPTION|CHARGE|FROM_DATE |TO_DATE |
+-------+-----------+------+----------------------+----------------------+
|1 |small |100 |01/01/2014 12:00:00 AM|31/03/2014 12:00:00 AM|
+-------+-----------+------+----------------------+----------------------+
|2 |mediam |200 |01/04/2014 12:00:00 AM|04/04/2014 12:00:00 AM|
+-------+-----------+------+----------------------+----------------------+
|3 |big |300 |05/04/2014 12:00:00 AM|31/12/2014 12:00:00 AM|
+-------+-----------+------+----------------------+----------------------+
Let the sample fee table in the date range be higher, I will have an input, as
start_date = to_date('30/mar/2014','dd/mon/yyyy')well as
end_date = to_date('05/apr/2014','dd/mon/yyyy').
Thus, the input dates are included for two days of charge 100 (rate_id = 1), 4 days of charge 200 and 1 day of charge 300 and all 1300.
Is there an easy way to find the number of days that exist in a given range so that I can calculate total_charge. I am currently using PL / SQL for the above, using loopto find existence.
In general: from the entrance,
30 and 31st march belongs to small(100 charge) => 100* 2 = 200
1, 2, 3, 4 of april belongs to medium( 200 charge) => 200*4 = 800
5th april belongs to big ( 300 charge) => 300*1 = 300
so
the total:= 200 + 800 + 300 = 1300
Thanks in advance.
source
share