› Fóruns › SQL e PL/SQL › Pegar Coluna e somar Mes a Mes é possivel? › Pegar Coluna e somar Mes a Mes é possivel?
[quote=”MARCIO_LOK”:19e8z928]Bom dia Pessoal
Eu tenho um select, que me tras os valores mensais, ele verifica se o valor é credito ou debito, soma e agrupa por mes, ate ai tudo bem….
Eu tenho um valor inicial 100.00, eu preciso vir subtraindo esse valor mensalmente é possivel isso?
Tipo Assim:
Valor de Dezembro – 100,00
Valor de Novembro – dezembro – 100,00
Valor de Outubro – novembro – dezembro – 100,00
(obs..esses 100.00 vou buscar em uma outra tabela, porque o valor nao é fixo, só usei o valor como exemplo)
Seria possivel isso? Por exemplo na coluna que aparece o valor de outubro, eu teria que jogar esse valor subtraindo novembro, dezembro e os 100,00… seria possivel?
Segue o Script abaixo:
Select
H.Descricao AS DESCRICAO, H.CodConta AS CODCONTAS
, Sum(Decode(To_Char(L.Data, ‘mm’),’01’,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
When Credito Is Not Null Then L.Valor End ) ) Janeiro
, Sum(Decode(To_Char(L.Data, 'mm'), '02',
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Fevereiro
, Sum(Decode(To_Char(L.Data, 'mm'), '03',
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Marco
, Sum(Decode(To_Char(L.Data, 'mm'), '04' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Abril
, Sum(Decode(To_Char(L.Data, 'mm'), '05' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Maio
, Sum(Decode(To_Char(L.Data, 'mm'), '06' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Junho
, Sum(Decode(To_Char(L.Data, 'mm'), '07' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Julho
, Sum(Decode(To_Char(L.Data, 'mm'), '08' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Agosto
, Sum(Decode(To_Char(L.Data, 'mm'), '09' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Setembro
, Sum(Decode(To_Char(L.Data, 'mm'), '10' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Outubro
, Sum(Decode(To_Char(L.Data, 'mm'), '11' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
when credito is not null then L.Valor end ) ) Novembro
, Sum(Decode(To_Char(L.Data, 'mm'), '12' ,
Case When Debito Is Not Null And
Partida Is Not Null Then -L.Valor
When Credito Is Not Null Then L.Valor End ) ) Dezembro
, Round(Sum(L.Valor * Case When Credito Is Not Null Then 1
When Debito Is Not Null Then -1 End),2) AS Total
, Round(Sum(L.Valor * Case When Credito Is Not Null Then 1
When Debito Is Not Null Then -1 End)/12,2) As Media
From Clanca L,Cconta C,Csdant S,
Ccontahistorico H
Where
H.Codcoligada = C.Codcoligada
And H.Codconta(+) = C.Codconta
And L.Codcoligada = C.Codcoligada
And (L.Credito = C.Codconta
Or L.Debito = C.Codconta)
And S.Codcoligada = C.Codcoligada
And S.Codconta = C.Codconta
And Substr(C.Codconta,1,1) = ‘1’
And To_Char(L.Data,’yy’) = ’09’
GROUP BY H.Descricao, H.CodConta
Order By H.Codconta
se alguem puder me ajudar, ele esta agrupando por conta…..
o resultado desse select é assim:
DESCRICAO CODCONTAS JANEIRO FEVEREIRO MARCO ABRIL ...ate dezembro...
1 CAIXA 12111900001 2522,94 5142,98 6828,2 10479,52
2 REAL ABN AMRO – C/C 5.710.132-5 12131900002 38456,98 -16161,01 17397,07 15358,87
3 UNIBANCO – C/C 822.506-6 12131900007 -2569,36 2446,17 -3180,08 3481,35
preciso jogar essas subtracoes embaixo dos meses, é possivel?[/quote]
Cara… acho que só utilizando tabelas temporárias e PLSQL.