Calcular el promedio de la columna de la consulta MYSQL
Ok expertos...Tengo una tabla que estoy tratando de calcular el promedio de los valores en una columna. Aquí está mi búsqueda:
$gameswon = mysql_query("SELECT SUM(P1_Score) AS value_sum FROM tblMatches Where P1_ID LIKE '".$playerid."'");
¿Alguna idea de cómo puedo determinar el promedio (suma de valores / filas totales)?
Gracias por su ayuda.
38
3 answers
Obviamente es
SELECT AVG(P1_Score)
73
Author: zerkms,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-06 02:36:03
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-06 02:36:03
Así que en su caso:
$gameswon = mysql_query("SELECT AVG(P1_Score) AS value_sum
FROM tblMatches
WHERE P1_ID LIKE '".$playerid."'");
8
Author: xQbert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-07 14:59:55
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-07 14:59:55
Intenta usar la función AVG () aggregate en lugar de SUM
$gameswon = mysql_query("SELECT AVG(P1_Score) AS value_sum FROM tblMatches Where P1_ID LIKE '".$playerid."' . "GROUP BY XXXX");
Y XXXX es la columna que desea obtener promedio para, por ejemplo, player
4
Author: GiantRobot,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-06 02:41:34
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-01-06 02:41:34