I have table with positions of car (from gps tracker) and I want to select positions of start and end of drive. So I should select first row where speed >0 and last where speed was >0 with specific date (day). How can I do this?
For example I have table with values:
+------+-------+---------------------+
| id | speed | date |
+------+-------+---------------------+
| 1 | 0 | 2015-02-03 10:00:00 |
| 2 | 10 | 2015-02-03 10:00:10 |
| 3 | 50 | 2015-02-03 10:00:20 |
| 4 | 100 | 2015-02-03 10:00:30 |
| 5 | 50 | 2015-02-03 10:01:00 |
| 6 | 0 | 2015-02-03 10:01:10 |
| 7 | 10 | 2015-02-03 12:00:10 |
| 8 | 50 | 2015-02-03 12:00:20 |
| 9 | 100 | 2015-02-03 12:00:30 |
| 10 | 50 | 2015-02-03 12:01:00 |
| 11 | 0 | 2015-02-03 12:01:10 |
+------+-------+---------------------+
And I need to select records with ids: 2,5,7,11
EDIT
This is the full list of columns : id (identity), car_id,altitude,latitude,longitude,speed,date
I need to calculate each track distance. (one car may drive many times in 1 day - it can drive from 6 am to 10 am, then stop on parking from 10 am to 1 pm and then again drive from 1pm to 5 pm.) So first I need to "detect" start and stop of driving (car also send data to database when it keeps on parking (speed=0) ),then calculate distance using something like this distance calculations in mysql queries
This is the database from http://www.traccar.org/ project.