Sql soma

Delphi

11/01/2006

olá

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

Fernando_cunha

Curtidas 0

Respostas

Aerreira

Aerreira

11/01/2006

Acho que nesse tópico [url]http://forum.clubedelphi.net/viewtopic.php?t=71939[/url] você vai encontrar solução para o seu problema.


GOSTEI 0
Fx|hand

Fx|hand

11/01/2006

SELECT SUM(valor) AS total, dc FROM t GROUP BY dc;



poxa velho... como q vc naum conseguiu fazer issu ?!


GOSTEI 0
Fx|hand

Fx|hand

11/01/2006

ou então... c vc precisar de subtotal !!!


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;



GOSTEI 0
Silviogs

Silviogs

11/01/2006

Olá amigo

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


GOSTEI 0
POSTAR