Fórum select sum() #324957
07/07/2006
0
estou fazendo um relatorio e preciso de um select para somar alguns campos, quero exibir no relatorio a nota, data, cfop, cst o total da nota e o valor do desconto, fiz como esta abaixo, funciona mas não é o que quero pois assim ele agrupa por nota, data, cfop e cst, quero agrupar apenas pela nota como faço?
select nota, data, cfop, cst, sum(vr1), sum(vr2) from tabela
group by nome1, nome2, nome3, nome4
select nota, data, cfop, cst, sum(vr1), sum(vr2) from tabela
group by nome1, nome2, nome3, nome4
Cpd_arim
Curtir tópico
+ 0
Responder
Posts
07/07/2006
Lehapan
select
nota, data, cfop, cst,
(select sum(vr1) from tabela tab1 where tab1.nota = tab.nota) AS TotVr1,
(select sum(vr2) from tabela tab2 where tab2.nota = tab.nota) AS TotVr2
from
tabela tab
group by
nota
Teste, pois eu não cheguei a testar.
nota, data, cfop, cst,
(select sum(vr1) from tabela tab1 where tab1.nota = tab.nota) AS TotVr1,
(select sum(vr2) from tabela tab2 where tab2.nota = tab.nota) AS TotVr2
from
tabela tab
group by
nota
Teste, pois eu não cheguei a testar.
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)