1407.sql (188B)
1 SELECT U.name, 2 IFNULL(SUM(R.distance), 0) AS travelled_distance 3 FROM Users U 4 LEFT JOIN Rides R 5 ON U.id = R.user_id 6 GROUP BY U.id 7 ORDER BY SUM(R.distance) DESC, 8 U.name ASC