sql help - generate HH slots based on timeslices
Date: Mon, 11 Sep 2017 13:37:29 -0700
Message-ID: <CAKsxbLr4F=+GMXtvq3kxQS4c0GFwajOxAbrqCHtLf6iEo68=Xw_at_mail.gmail.com>
Hi all I am need of some SQL help. Maybe because it is a Monday or my brain is just slow today. I am having trouble figuring out how to do this. I have IN and OUT time slices for an employee and I need to break that into half hour slices and the number of minutes worked in that half, relating to the business date or labor date.
So for example say I had a table like below:
create table labor_data (
emp_id number,
labor_date date,
in_time date,
out_time date);
insert into labor_data (EMP_ID, LABOR_DATE, IN_TIME, OUT_TIME)
values (10000, to_date('01-09-2017', 'dd-mm-yyyy'), to_date('01-09-2017
16:30:00', 'dd-mm-yyyy hh24:mi:ss'), to_date('01-09-2017 21:28:00',
'dd-mm-yyyy hh24:mi:ss'));
I would like to generate something like below. I am flexible in how the half hours slots look like.
emp
labor_date
hh_slot
hh_time
minutes
10000
9/1/2017
1630
16:30
30
10000
9/1/2017
1700
17:00
30
10000
9/1/2017
1730
17:30
30
10000
9/1/2017
1800
18:00
30
10000
9/1/2017
1830
18:30
30
10000
9/1/2017
1900
19:00
30
10000
9/1/2017
1930
19:30
30
10000
9/1/2017
2000
20:00
30
10000
9/1/2017
2030
20:30
30
10000
9/1/2017
2100
21:00
28
10000
9/1/2017
2230
21:30
0
10000
9/1/2017
2300
22:00
26
10000
9/1/2017
2330
22:30
30
10000
9/1/2017
2400
23:00
30
10000
9/1/2017
2430
23:30
30
10000
9/1/2017
2500
0:00
30
10000
9/1/2017
2540
0:30
30
10000
9/1/2017
2600
1:00
30
10000
9/1/2017
2630
1:30
30
10000
9/1/2017
2700
2:00
30
10000
9/1/2017
2730
2:30
25
Thanks,
Jeff
-- http://www.freelists.org/webpage/oracle-lReceived on Mon Sep 11 2017 - 22:37:29 CEST