-Karl- Posted May 16, 2010 Share Posted May 16, 2010 I have a table called members, in it I have usernameurlattack An example would be myusernamewww.google.com99 anotherusernamewww.phpfreaks.com95 What I want to do is calculate averages. So select all the information from the members table. Then group the result by their url, and carry out a calculation. The calculation would be easy. Add up all the levels (attack), divided by the amount of users with that url. I'm not sure how to go about getting the data and splitting it however, then I'd carry out the calculation and echo the highest number, followed by the clanurl. Any ideas? Link to comment https://forums.phpfreaks.com/topic/201979-averages-based-on-information-from-a-database/ Share on other sites More sharing options...
Mchl Posted May 16, 2010 Share Posted May 16, 2010 SELECT url, AVG(attack) FROM members GROUP BY url Link to comment https://forums.phpfreaks.com/topic/201979-averages-based-on-information-from-a-database/#findComment-1059245 Share on other sites More sharing options...
-Karl- Posted May 16, 2010 Author Share Posted May 16, 2010 Oh wow, there's a MySQL function for it? I should do more research. Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/201979-averages-based-on-information-from-a-database/#findComment-1059247 Share on other sites More sharing options...
-Karl- Posted May 16, 2010 Author Share Posted May 16, 2010 Umm, how would I select the max from this result, and the clanurl appropriate to the max? Link to comment https://forums.phpfreaks.com/topic/201979-averages-based-on-information-from-a-database/#findComment-1059251 Share on other sites More sharing options...
Mchl Posted May 17, 2010 Share Posted May 17, 2010 SELECT url, AVG(attack) AS attack FROM members GROUP BY url ORDER BY attack DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/201979-averages-based-on-information-from-a-database/#findComment-1059360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.