-2
How do I add all user points? For example:
ID | NOME | PONTOS
1 | Joao | 100
2 | Bia | 50
It is known that the sum of all the points in the database is 150.
-2
How do I add all user points? For example:
ID | NOME | PONTOS
1 | Joao | 100
2 | Bia | 50
It is known that the sum of all the points in the database is 150.
9
Summing up:
SELECT SUM(PONTOS) AS total
FROM tabela
Adding up by users:
SELECT NOME, SUM(PONTOS) AS total
FROM tabela
GROUP BY NOME
Counting the amount of records per user:
SELECT NOME, COUNT(PONTOS) AS registros
FROM tabela
GROUP BY NOME
Displaying the average per user:
SELECT NOME, AVG(PONTOS) AS media
FROM tabela
GROUP BY NOME
All up together:
SELECT NOME, SUM(PONTOS) AS total, COUNT(PONTOS) AS registros, AVG(PONTOS) AS media
FROM tabela
GROUP BY NOME
See working on Sqlfiddle
DISTINCT and GROUP BY, what is the difference between the two statements?
Browser other questions tagged mysql
You are not signed in. Login or sign up in order to post.
SELECT SUM(PONTOS) AS total FROM tabela;
– Andrei Coelho
obgd, I will test
– Carlos Barros