-1
I need to select the 3 users with the highest revenue. Before in the table cde_usuario there was a column called scythe, being very simple to make this query, used this sql:
$sql = "SELECT * FROM cde_usuario ORDER BY qtdreceita DESC LIMIT 3";
However, this column has been removed as the table now exists cde_venda_detail, being one of the columns id_client and value. Now I need to add up all the numbers in the column value of all customers with purchases, and in the end select the 3 customers that resulted in the highest value.
I know that to add up the total value of all purchases of a specific user is like this:
$sql = "SELECT SUM(valor) as total FROM cde_venda_detalhe WHERE id_cliente = $idCliente";
But I don’t know how to "unite" these Selects, if anyone can help me thank you.
Yes, it worked perfectly, thank you!
– Afuro Terumi