1
I have doubts about how to perform the query displaying two fields, with only one.
I have the Clients Table (id, name, date of birth) and the Transactions table (id_trans
, id_clien
, valor_trans
).
I need the query to show the total spent per client with the fields: nome_clie
, id_clie
, total_trans
).
When I try to add a second column to display the error, it only works with name and total spent.
This is my query that works, I need it to also display the client ID, only the name appears.
select
nm_cli,
sum(vl_trn) as tot_trn
from
tb_cli left join tb_trn on (tb_cli.id_cli = tb_trn.id_cli)
group by nm_cli;
What is the error that gives and which SQL was executed?
– Woss
Error Code: 1052. Column 'id_cli' in field list is ambiguous
– Kallebhalf
select nm_cli,
sum(vl_trn) as tot_trn
from tb_cli
 left join tb_trn
 on (tb_cli.id_cli = tb_trn.id_cli)
 group by nm_cli;
– Kallebhalf