a partir de una tabla: encargos
necesito hacer un consulta donde debo obtener una tabla seleccionada entre fechas
articulo, ventas1, ventas2, ventas3, ventas4, ventas5, ventas6, ventas7
y lo hago con el UNION ALL
Código SQL:
Ver original(SELECT encargos.monturaVta AS montura, COUNT(*) AS ventastda1 , 0 AS ventastda2, 0 AS ventastda3, 0 AS ventastda4, 0 AS ventastda5, 0 AS ventastda6, 0 AS ventastda7
FROM encargos
WHERE encargos.fechaVta>='2017-01-30' AND encargos.fechaVta<='2017-02-06' AND
encargos.tdaVta=1 AND encargos.monturaVta>''
GROUP BY encargos.monturaVta)
UNION ALL
(SELECT encargos.monturaVta AS montura, 0 AS ventastda1, COUNT(*) AS ventastda2, 0 AS ventastda3, 0 AS ventastda4, 0 AS ventastda5, 0 AS ventastda6, 0 AS ventastda7
FROM encargos
WHERE encargos.fechaVta>='2017-01-30' AND encargos.fechaVta<='2017-02-06' AND
encargos.tdaVta=2 AND encargos.monturaVta>''
GROUP BY encargos.monturaVta)
UNION ALL
(SELECT encargos.monturaVta AS montura, 0 AS ventastda1, 0 AS ventastda2, COUNT(*) AS ventastda3, 0 AS ventastda4, 0 AS ventastda5, 0 AS ventastda6, 0 AS ventastda7
FROM encargos
WHERE encargos.fechaVta>='2017-01-30' AND encargos.fechaVta<='2017-02-06' AND
encargos.tdaVta=3 AND encargos.monturaVta>''
GROUP BY encargos.monturaVta)
[/CODE]
esto me saca una tabla tal:
art1 1 0 0 0 0 0 0
art1 0 1 0 0 0 00
art2
art2
art2
es decir, por cada select una linea,
cómo puedo hacer que me agrupe por articulo el resultado final?