I have the following MYSQL query:
SELECT SUM(A.val) AS totalvendas, B.cod AS codigo, B.nom AS Nome, B.reg AS regiao FROM venda AS A LEFT JOIN vendedor AS B ON A.ven = B.cod WHERE reg = "norte" GROUP BY A.ven ORDER BY totalvendas DESC;
It returns me the following:
totalvendas | codigo | Nome | regiao
-----------------------------------
144 | 1 |Sr. A | Norte
93 | 10 |Sr. J | Norte
49 | 16 |Sr. Q | Norte
42 | 6 |Sr. F | Norte
30 | 5 |Sr. E | Norte
1 | 12 |Sr. M | Norte
What I want after the select, is to make a new select but to return only those that have the SOMA greater than 45 for example, I just want to play a number in this select and can only have the desired result. If by chance I add in the above select in WHERE one:
AND totalvendas > 45
So:
SELECT SUM(A.val) AS totalvendas,B.cod AS codigo, B.nom AS Nome, B.reg AS regiao FROM venda AS A LEFT JOIN vendedor AS B ON A.ven = B.cod WHERE reg = "norte" AND totalvendas > 45 GROUP BY A.ven ORDER BY totalvendas DESC;
It becomes an invalid query ... How can I solve this problem without having to stock the totals in temporary tables?
Thank you.