There are two tables - users and their purchases:
users id name statistics id sum user_id It is necessary, in general, to select all users by the total amount for which they bought.
I make a request, for some reason it does not work:
SELECT user.* FROM users, (SELECT SUM(statistics.sum) FROM statistics) as sum ORDER BY sum DESC