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 :) 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] 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. 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
Archived
This topic is now archived and is closed to further replies.