I understand this question was answered here:
Oracle, split a time duration row by one hour period
but, what about if you have multiple time periods like this:
I have the following query:
select AdmitDate, PatientName, Room, greatest(start_time, trunc(start_time+(level-1)/24, 'hh24')) beginTime, least(end_time, trunc(start_time+(level)/24, 'hh24')) endTime
from Utilization
connect by level <= floor((trunc(end_time, 'hh')-trunc(start_time, 'hh'))*24)+1
but it returns the results below which appears to be incorrect.
If I have a single time row table it works great.
Is there a way I can group the results by PatientName or just each row calculated separatly?