So maybe my question title is not most relevant but I’m not good in sql and I will need to learn it for sure (So hint for some book would be very useful)
Anyhow I got table which has following (important) columns:
user_id,username,revenue
and records like this:
1,john,39
2,mark,53
3,philipp,7
1,john,17
2,mark,3
2,mark,100
I need to get user who has the biggest revenue, so I need to get all rows, calculate total earnings and print the user who has the biggest revenue in total.
Any hints 😉 ?
You can use
ORDER BYandLIMIT:With this, you’ll calculate the revenue for each user, you order by decreasing total and get only the first one, so that you have the highest revenue.