-1
I have 2 tables, one called and another client, I need to return how many calls the client had in the current month, last month and last month, tried using Union, he returned me normally, but, I can only make a Count.
SELECT
COUNT(*) AS total_chamado,
from chamado, cliente
where
chamado.id_cliente = cliente.id AND
GROUP BY chamado.id_cliente
union
(
SELECT
COUNT(*) AS total_chamado_passado,
from chamado, cliente
where
chamado.id_cliente = cliente.id AND
chamado.data_atendimento BETWEEN CURDATE() - INTERVAL 1 month AND CURDATE()
GROUP BY chamado.id_cliente
)
You can use IF and SUM in your field list. Type SUM(IF(field_to test = 2, 1, 0)) The numero_result
– Peter