Ayuda con una consulta

18/05/2006 - 00:36 por Juan Huachaca Gomez | Informe spam
AMigos ayudenme con esto

Tengo esta tabla:
codigo ciudad total tipo
042006 001 340 1
042006 001 340 2
042006 001 220 1

deseo tener este resultado
codigo ciudad total1 total 2 saldo
042006 001 560 340 220

Como lo puedo hacer ???

Salu2

Juan Huachaca Gomez
MSN: j_huachaca79@yahoo.es
Telf. (00511) 7809892
 

Leer las respuestas

#1 Alejandro Mesa
18/05/2006 - 02:30 | Informe spam
How to rotate a table in SQL Server
http://support.microsoft.com/defaul...roduct=sql

select
codigo,
ciudad,
sum(case when tipo = 1 then total else 0 end) as total1,
sum(case when tipo = 2 then total else 0 end) as total2,
sum(case when tipo = 1 then total else 0 end) - sum(case when tipo = 2
then total else 0 end) as saldo
from
tu_tabla
group by
codigo, ciudad
go


AMB

"Juan Huachaca Gomez" wrote:

AMigos ayudenme con esto

Tengo esta tabla:
codigo ciudad total tipo
042006 001 340 1
042006 001 340 2
042006 001 220 1

deseo tener este resultado
codigo ciudad total1 total 2 saldo
042006 001 560 340 220

Como lo puedo hacer ???

Salu2

Juan Huachaca Gomez
MSN:
Telf. (00511) 7809892




Preguntas similares