0
I have 3 tables, and need to make a SELECT inside a LOOP on 3 at the same time, would be as follows:
note that the result, I take the username where it would be in the column NAME, I DO a num_rows to display the quantity of sales and add in SALES and the sum of the products sold by each user.
I found some similar things on the site, but I couldn’t adapt... I tried something like, but I can’t adapt it to my case.
SELECT a.ticket_lote_id,
COALESCE(SUM(b.lote_preco), 0) AS lote_preco
FROM vendidos a LEFT JOIN ingress b ON b.lote_id = a.ticket_id
GROUP BY a.venda_id
I tested this way, but he returned me a total value of all... not of user per user... I tried to put inside the loop (WHILE) but it still returns me only 1 result and the wrong total value too. (this summing of all users, not each user in a list).
– user169890
edited the query now grouped by username
– Jasar Orion