Count rows that have the same value in 2 different columns?

2

Table

ID    jogada    pontos
1       1          3
1       1          1
2       5          1 
2       5          1
2       5          3
2       5          3

I wanted to create a query that counts the play lines and sums the total of points, but that indicates the sum by repeating the "ID" like this:

Return I hope:

ID    contar_jogada    somar_pontos
1       2                   4
2       4                   8 
    
asked by anonymous 05.06.2017 / 04:03

1 answer

4

Use the SUM function to add the points, COUNT to count the plays and Group By to group by ID.

Query

SELECT id AS ID, 
Count(jogada) AS TotalJogada, 
Sum(pontos)   AS Pontos 
FROM   tablename 
GROUP  BY id 
    
05.06.2017 / 05:51