t_machine Posted November 15, 2006 Share Posted November 15, 2006 hi, I can't seem to figure out why the query is failing. I run it on my local host and it works but when placed online it fails.$wpoints = query_db("select u_id, SUM(points) from table where b_id='2' group by u_id order by SUM(points)");When I try to get a numrows it shows blank online but on local host it shows the correct amount.The table contains u_id, points and b_idThe b_id is a category id, u_id is the user and then points.The u_id is entered a number of times in the table with points. I would like to sum the points for each u_id and order them by the ones with the most points.Any help would be greatly appreciated :) Quote Link to comment https://forums.phpfreaks.com/topic/27335-what-is-wrong-with-this-sum-query/ Share on other sites More sharing options...
obsidian Posted November 15, 2006 Share Posted November 15, 2006 Try naming your aggregate and ordering by that name:[code]SELECT u_id, SUM(points) AS points FROM table WHERE b_id = '2' GROUP BY u_id ORDER BY points;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27335-what-is-wrong-with-this-sum-query/#findComment-125003 Share on other sites More sharing options...
t_machine Posted November 16, 2006 Author Share Posted November 16, 2006 Thank you very much :) Works perfectly now. Quote Link to comment https://forums.phpfreaks.com/topic/27335-what-is-wrong-with-this-sum-query/#findComment-125618 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.