How do I add up all user points? For example:
ID | NOME | PONTOS
1 | Joao | 100
2 | Bia | 50
It is known that the sum of all points in the database is 150.
How do I add up all user points? For example:
ID | NOME | PONTOS
1 | Joao | 100
2 | Bia | 50
It is known that the sum of all points in the database is 150.
Summing up:
SELECT SUM(PONTOS) AS total
FROM tabela
Adding 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 together above:
SELECT NOME, SUM(PONTOS) AS total, COUNT(PONTOS) AS registros, AVG(PONTOS) AS media
FROM tabela
GROUP BY NOME
See working in SQLFiddle
DISTINCT and GROUP BY, what's the difference between the two statements?