-1
Good afternoon, everyone,
I have two queries that work perfectly separate, but need to display in a grid information of the two queries.
I need to take all the inputs of a product and put in a column and in another column the outputs...
I made the so:
SELECT CODIGO, DESCRICAO,
(SELECT SUM(Produtos_Quant.QUANT) AS Expr1
FROM Produtos_Quant INNER JOIN
produtos AS A ON Produtos_Quant.COD_PRODUTO = C.CODIGO
WHERE (Produtos_Quant.TIPO <> 'REMOÇÃO')
GROUP BY Produtos_Quant.COD_PRODUTO) AS vEntradas,
(SELECT SUM(pedidos_itens.QUANTIDADE) AS Expr1
FROM pedidos_itens INNER JOIN
produtos AS B ON pedidos_itens.COD_PRODUTO = C.CODIGO INNER JOIN
pedidos ON pedidos_itens.COD_PEDIDO = pedidos.COD_PEDIDO
WHERE (pedidos_itens.cancelado = 0) AND (pedidos.TIPO_PEDIDO <> 'ORÇAMENTO')
GROUP BY pedidos_itens.COD_PRODUTO) AS vSaidas
FROM produtos AS C
Make no mistake... but the result goes wrong.
Example:
Making the separate inquiry the REPELEX product has 13 inputs and 12 outputs
Now making that way the same product has 76608 inputs and 82992 outputs
I need to place a product in each line with its inputs and outputs (sum).
Where am I going wrong?
put in the question the structure of the tables and some sample data to help realize better what is wrong
– Ricardo Pontual
take the groupy by of the queries , having the model sure can improve the query
– Motta