I need help with a problem. Actually, I do not know if it will be possible to solve it directly in SQL.

I have a list of works. Each work has a start date and ending date, with this format 

```
YYYY/MM/DD  HH24:MI:SS

```

I need to calculate the cost of those jobs, the hour price depends on the time intervals in which the work has been done:

```
Nigth time: 22:00 to 6:00, for example: 20 €/h
Normal time: the rest 17 €/h

```

So, if I have a sample like this:

```
wo     start                 end
21    2017/11/16 21:25:00    2017/11/16 22:55:00
22    2017/11/17 05:45:00    2017/11/17 07:05:00
23    2017/11/18 23:00:00    2017/11/19 1:10:00
24    2017/11/17 18:00:00    2017/11/17 19:00:00

```

I would need to calculate the intervals of the dates between the 22h and 6h and the rest to multiply them by their corresponding price

```
wo     rest(minutes)   night(minutes)
21      35              55
22      15              65
23       0              130
24       1               0

```

Thank for your help in advance.