I have table like this :
+-------------+---------------------+---------------------+--------+
| id | name | start_time | end_time | score |
+-------------+---------------------+---------------------+--------+
| 1 | Jon | 2017-10-19 01:00:00 | 2017-10-19 01:20:00 | 20 |
| 2 | Jane | 2017-10-19 01:15:00 | 2017-10-19 01:30:00 | 20 |
| 3 | Fred | 2017-10-19 01:00:25 | 2017-10-19 03:10:35 | 80 |
| 4 | July | 2017-10-19 01:12:28 | 2017-10-19 01:16:35 | 10 |
+-------------+---------------------+---------------------+--------+
I want this:
+-------------+---------------------+---------------------+--------+-------+
| id | name | start_time | end_time | score | rank |
+-------------+---------------------+---------------------+--------+-------+
| 3 | Fred | 2017-10-19 01:00:25 | 2017-10-19 03:10:35 | 80 | 1 |
| 2 | Jane | 2017-10-19 01:15:00 | 2017-10-19 01:30:00 | 20 | 2 |
| 1 | Jon | 2017-10-19 01:00:00 | 2017-10-19 01:20:00 | 20 | 3 |
| 4 | July | 2017-10-19 01:12:28 | 2017-10-19 01:16:35 | 10 | 4 |
+-------------+---------------------+---------------------+--------+-------+
Basically, I want order by score. If the scores are equal, then order by lowest duration time. this is different from ordering just by score , it should also calculate duration from start_time and end_timer