Join 2 SQL with different results [closed]

-1

asked by anonymous 27.01.2017 / 16:43

1 answer

1

So

SELECT SUM(Temp.ordem) as ordem, sum(Temp.sistema) as sistema from
(SELECT COUNT(a.arquivada=1)AS orden, 0 as sistema
FROM tbl_os o
INNER JOIN tbl_clientes c ON(o.tecnico = c.id)
WHERE o.arquivada=1 AND o.tecnico=1 AND DAY(o.dataSaida)=x AND MONTH(o.dataSaida) = x
UNION ALL
SELECT 0 as ordem, SUM(a.idTipoAtendimento=1) AS sistema, SUM(a.idTipoAtendimento=2)AS servico, c.nomeCliente FROM tbl_Atendimento a
INNER JOIN tbl_clientes c ON(a.tecnico = c.id)
WHERE a.arquivada=1 AND a.tecnico=1 AND DAY(a.dataMarcada)=x AND MONTH(a.dataMarcada) = x)
as Temp

What we do before joining the two queries is to ensure that they have the same columns, so SELECT ... 0 the order ...

Next, I use the Sum (Time.order) so that both results are on the same line.

    
28.01.2017 / 06:13