Unir 2 selects
Olá pessoal, estou com a dificuldade em unir dois selects seria mais ou menos o seguinte
tabela:
produto int
quantidade int
operacao int
estou com os seguintes selecs
select produto,
sum(quantidade) as qtd
from VW_RELATORIO_VOLUME_VENDAS
where operacao < 2 and dt_digitacao Between :MDataI and :MDataF
group by 1
select produto,
sum(quantidade) as qtd1
from VW_RELATORIO_VOLUME_VENDAS
where operacao > 2 and dt_digitacao Between :MDataI and :MDataF
group by 1
eu preciso obter o seguinte resultado A NILVE DE COLUNAS
PRODUTO | QTD | QTD1
1 | 2 | 3
2 | 1 | 0
3 | 0 | 2
ja tentei pelo UNION, UNION ALL, porem nao funcionou
vlw
Ricardo
tabela:
produto int
quantidade int
operacao int
estou com os seguintes selecs
select produto,
sum(quantidade) as qtd
from VW_RELATORIO_VOLUME_VENDAS
where operacao < 2 and dt_digitacao Between :MDataI and :MDataF
group by 1
select produto,
sum(quantidade) as qtd1
from VW_RELATORIO_VOLUME_VENDAS
where operacao > 2 and dt_digitacao Between :MDataI and :MDataF
group by 1
eu preciso obter o seguinte resultado A NILVE DE COLUNAS
PRODUTO | QTD | QTD1
1 | 2 | 3
2 | 1 | 0
3 | 0 | 2
ja tentei pelo UNION, UNION ALL, porem nao funcionou
vlw
Ricardo
Ricardo Matarazzo
Curtidas 0
Respostas
Claudia Nogueira
20/12/2012
Tenta assim:
SELECT produto,
SUM(CASE WHEN operacao < 2 THEN quantidade ELSE 0 END) AS qtd,
SUM(CASE WHEN operacao > 2 THEN quantidade ELSE 0 END) AS qtd1
FROM VW_RELATORIO_VOLUME_VENDAS
WHERE (operacao <> 2)
AND (dt_digitacao between :MDataI AND :MDataF)
GROUP BY 1
GOSTEI 0
Ricardo Matarazzo
20/12/2012
blz... obrigadão
GOSTEI 0