I have a MySQL database with a table that has a field/column labled "user8" (which is the field for users' state). I have this PHP call and its working fine if I call all states individually and I only want numbers of rows. <?PHP mysql_select_db("my_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM `users` WHERE `user8` LIKE '%Georgia%' "); $num_rows = mysql_num_rows($result); echo $num_rows - Georgia\n; ?> Code (markup): I would like the MySQL call and the PHP to echo out the lists of all states by percentage. i.e. United States 50% Candana 30% etc. This is what I have so far. <?PHP mysql_select_db("my_database") or die(mysql_error()); $result = mysql_query("SELECT user8, COUNT(*) AS Total, SUM(in) AS TotalIn, SUM(in)*100/COUNT(*) AS Percent FROM lm_users GROUP BY user8 "); $num_rows = mysql_num_rows($result); echo $num_rows \n; ?> Code (markup): It should work, but doesn't. Any help would be appreciated. Thanks
I also think it would make sense to do the calculations away from the database in this case. However, it should be possible to do directly. I don't really understand the database structure though. "lm_user" is another table? What is the "in" field? The problem in your query is the group by which you can not use along with sum in that manner.