Avatar of Stef Merlijn
Stef Merlijn
Flag for Netherlands

asked on 

SQL question (expert)

Hi,

This is a real chalenge:
In my table I have the following fields:
- Function (Integer) Lookupfield in table Functions
- Daynr (Integer) 1-7 = mon-sun
- Starttime (Time)
- Endtime (Time)
- Number (Integer)

For each Function (Jobdescr.) one or more timeblocks (Start-Endtime) can be present in the table for one or multiple days (Daynr).
If for some Function more than one timeblock is planned for the same day, then a separate row will be presented (see function 1).

The Start- and Endtime can be converted to a stringvalue and, if at all possible, also the field Number should be added on a separate line within the same field where the timeblock is presented. Maybe that can be done by using some calculated field?

Can anybody help with getting the following output?
Thanks, Stef
Content of table:
 
Function  Daynr  Starttime  Endtime Number
   1        1      08:00     16:00    3
   1        2      10:00     18:00    2
   1        3      08:00     16:00    1
   1        4      22:00     06:00    1
   1        5      08:00     16:00    2
   1        6      08:00     16:00    1
   1        7      08:00     16:00    1
   1        2      00:00     08:00    2
   1        3      18:00     22:00    1
   1        5      11:00     15:00    2
   1        6      18:00     23:00    1
   1        7      08:00     16:00    1
   2        1      08:00     16:00    1
   2        4      22:00     06:00    1
   2        5      13:00     19:00    2
   2        6      08:00     16:00    3
   2        7      08:00     16:00    2
   3        2      10:00     18:00    2
   3        4      22:00     06:00    1
   3        6      14:30     21:30    2
   3        7      08:45     16:45    3
 
 
Result:
 
Function    Mon         Thu         Wed         Thu         Fri         Sat         Sun
-----------------------------------------------------------------------------------------------
function 1  08:00-16:00 10:00-18:00 08:00-16:00 22:00-06:00 08:00-16:00 08:00-16:00 08:00-16:00
                 3           2           1           1           2           1           1
function 1              00:00-08:00 18:00-22:00             11:00-15:00             18:00-23:00
                             2           1                       1                       1
function 2  08:00-16:00                         22:00-06:00 13:00-19:00 08:00-16:00 08:00-16:00
                 1                                   1           2           3           2
function 3              10:00-18:00             22:00-06:00             14:30-21:30 08:45-16:45
                             2                       1                       2           3

Open in new window

DelphiSQL

Avatar of undefined
Last Comment
Stef Merlijn

8/22/2022 - Mon