StreamMe Posted March 19, 2008 Share Posted March 19, 2008 Using mysql 5 Im trying to order the top 10 users (table1) by a total points(table2) 1 user may have multiple items with points, so it would have to SUM all the points for each user. can someone give me a lead in on this? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 19, 2008 Share Posted March 19, 2008 Once you join the two tables, a simple group by, sum(), and order by should make this quite easy. Quote Link to comment Share on other sites More sharing options...
StreamMe Posted March 20, 2008 Author Share Posted March 20, 2008 ive given up on this two table issue as its just....a pain lets try 1 table SELECT distinct user_id,* FROM video GROUP BY SUM(rating_total_points) DESC What am I doing wrong here? - keep in mind there are several videos so the order its like 1)sum all the rating_total_points by user_id 2)order user_id by total desc Im sure this is really simple but ive spent too many hours on it now im just frazzled Quote Link to comment Share on other sites More sharing options...
fenway Posted March 20, 2008 Share Posted March 20, 2008 Don't you mean: SELECT distinct user_id,SUM(rating_total_points) AS total FROM video GROUP BY distinct user_id ORDER BY total DESC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.