Canman2005 Posted November 4, 2008 Share Posted November 4, 2008 Hi all I have a simple table which looks like ID USER PRICE 1 10 12.00 2 21 5.00 3 21 10.00 What I want to do is run a query and return all results with the `USER` with the highest value at the top. So with my example above, `USER` ID 10 has a total of 12.00 (ROW 1) and `USER` has a total of 15.00 (5.00 + 10.00) (ROW 2 and 3) So it would therefore return USER TOTAL 21 15.00 10 12.00 Can anyone help? Much love Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/ Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 SELECT user,SUM(price) AS total FROM tableName GROUP BY user ORDER BY total DESC Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/#findComment-682165 Share on other sites More sharing options...
Maq Posted November 4, 2008 Share Posted November 4, 2008 Am I seeing things? I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user? I was just about to post it and I swear it just changed... ??? Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/#findComment-682170 Share on other sites More sharing options...
Canman2005 Posted November 4, 2008 Author Share Posted November 4, 2008 You legend, cheers Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/#findComment-682178 Share on other sites More sharing options...
rhodesa Posted November 4, 2008 Share Posted November 4, 2008 Am I seeing things? I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user? I was just about to post it and I swear it just changed... ??? i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/#findComment-682201 Share on other sites More sharing options...
Maq Posted November 4, 2008 Share Posted November 4, 2008 Am I seeing things? I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user? I was just about to post it and I swear it just changed... ??? i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me Hehe, just wanted to make sure I wasn't seeing things. Link to comment https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/#findComment-682204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.