2
The story is this: a politician can vote for several zonas
, therefore the reason for the same ID
candidate contain multiple records within the table.
The ID_CANDIDATO
being 120000000171
, he having 6 records in the database referring to the 6 different zones he received votes.
How to mount a sql
that will show 1
registration with all the information of this candidate and the total of votes received by it?
ID ID_CANDIDATO TOT_VOTOS
21 120000000171 339
45 120000000171 405
73 120000000171 513
88 120000000171 380
92 120000000171 752
96 120000000171 439
A visual example of what I’m looking for is on this page. The last field is the TOT_VOTOS
.
All data is within the same table. It can help me to extract the
SUM
and the rest of the information? Thank you.– Marcos Vinicius
SELECT *, SUM(TOTAL_VOTOS) as total_votos FROM VOTACAO_CANDIDATO_MUN_ZONA_2012_MS WHERE NOME_MUNICIPIO = 'CAMPO GRANDE' GROUP BY SQ_CANDIDATO
, thank you old man !!!– Marcos Vinicius