You can do it in SQL:
SELECT a.* FROM MyTable a
JOIN (SELECT Number, MAX(current_dist) as m FROM MyTable GROUP BY Number) b ON a.Number = b.Number
WHERE a.current_dist > m - 5000 AND a.Number = 600
ORDER BY current_dist DESC
"its work but can you explain it for me please and thanks"
It's pretty simple:
You have an "inner query" which returns the car number, and the maximum current_dist value for each car:
SELECT Number, MAX(current_dist) as m FROM MyTable GROUP BY Number
You then join that to each of the main table, so that each row has its maximum distance associated with it.
SELECT a.* FROM MyTable a
JOIN (...) b ON a.Number = b.Number
You then just filter it with a WHERE clause to get your "rows above distance":
WHERE a.current_dist > m - 5000 AND ...
and specific car number:
WHERE ... AND a.Number = 600
The final line just tells it to return them in descending order of current distance.
ORDER BY current_dist DESC
Have a look at W3Schools:
SQL GROUP BY Statement[
^]
SQL Joins[
^]
They will explain them better than I could! :laugh: