Sql soma
11/01/2006
0
eu tenho uma tabela que é assim:
Codigo Descricao Valor D/C
00001 Agua 100,00 D
00002 Salario 1.000,00 C
1 - como eu faço para somar todos os D e dar um Sub total ?
2 - como eu faço para somar todos os C e da um Sub Total separado ?
3 - Pegar os C e subtrair os D?
grato...
se souber fazer o 1º ou o 2º eu chego no terceiro rapidinho hehehe
obrigado
Fernando_cunha
Posts
11/01/2006
Aerreira
12/01/2006
Fx|hand
SELECT SUM(valor) AS total, dc FROM t GROUP BY dc;
poxa velho... como q vc naum conseguiu fazer issu ?!
12/01/2006
Fx|hand
SELECT SUM(valor) AS total, dc as tipo FROM t GROUP BY tipo union SELECT (select sum(valor) as total from t where dc = ´c´) - (select sum(valor) from t where dc = ´d´) as Total, ´SubTotal´ as tipo;
12/01/2006
Silviogs
vc pode usar assim também:
select (select sum(valor) from teste where tipo=´C´) as totc,
(select sum(valor) from teste where tipo=´D´) as totd,
(select sum(valor) from teste where tipo=´C´) - (select sum(valor) from teste where tipo=´D´) as total
Atenciosamente
Silvio Guedes
Clique aqui para fazer login e interagir na Comunidade :)