PHP / MySQL Select total balance of 1 client in the table

1

My client JOSÉ appears 4 times on this table, and I wanted to get his balance total. How do I do this?

tabela "clientes"
ID    NOME    SALDO
1     josé     10
1     josé     20
1     josé     30
4     maria    50
5     marta    60
1     josé     100
7     ana      70
8     sara     80

Total de JOSÉ: 160

I'd like it to be a simple query like this:

$sql = mysql_query("SELECT user_login FROM clientes ????????? WHERE ID = 1");
    
asked by anonymous 21.09.2017 / 21:04

1 answer

1

Use the "sum" function to add values from a given field:

$sql = mysql_query("SELECT sum(saldo) FROM clientes WHERE ID = 1");

Edit:

If the field "ID" contains a primary key (PK), you should search by name:

$sql = mysql_query("SELECT sum(saldo) FROM clientes WHERE NOME = 'josé'");
    
21.09.2017 / 21:22