I have a table that looks like this.
id date_from date_to description vehicle
1 2015-10-21 08:00 2015-10-21 10:00 GARAGE TO CLIENT 1 1
2 2015-10-21 12:00 2015-10-21 13:00 CLIENT 2 TO GARAGE 1
3 2015-10-21 14:00 2015-10-21 15:00 RET GARAGE 1
4 2015-10-21 18:00 2015-10-21 19:00 GARAGE TO CLIENT 1 1
5 2015-10-21 20:00 2015-10-21 21:00 CLIENT 2 TO GARAGE 1
6 2015-10-21 21:00 2015-10-21 22:00 RET GARAGE 1
I need to get the total time that the vehicle is in use. He stops being in use on first line and stops on the first description that starts with "RET".
A table like that would return
vehicle starts stops
1 2015-10-21 08:00 2015-10-21 15:00
1 2015-10-21 18:00 2015-10-21 22:00