We saw the Rank Function in my previous post for sorting records. In the same way using the function we can get the count of leaves taken in alternate intervals with a month for an employee.
For example:
Leaves taken on 1,2,3,4 of a month and came to office on 5th and again went on leave from 6th. the summary of absence using the query can be obtained.
For example:
Leaves taken on 1,2,3,4 of a month and came to office on 5th and again went on leave from 6th. the summary of absence using the query can be obtained.
select min(date_taken) date_from,
max(date_taken) date_to,
count(*) num_days
from (
select date_taken,
date_taken-row_number() over(order by date_taken) as daysto
from Absence
)
group by daysto
order by 1
DATE_FROM | DATE_TO | NUM_SAMPLES |
---|---|---|
01-DEC-15 | 04-DEC-15 | 4 |
07-DEC-15 | 10-DEC-15 | 4 |
14-DEC-15 | 16-DEC-15 | 3 |
19-DEC-15 | 20-DEC-15 | 2 |