Query

23/05/2006 - 19:37 por Juan Huachaca Gomez | Informe spam
AMigos ayudenme con esto (tengo SQL 2000)

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
23/05/2006 - 19:45 | Informe spam
Trata:

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
t1
group by
codigo,
ciudad
go

How to rotate a table in SQL Server
http://support.microsoft.com/defaul...roduct=sql

En la version 2005, quentas con los operadores PIVOT / UNPIVOT para hacer
este tipo de operaciones.


AMB

"Juan Huachaca Gomez" wrote:

AMigos ayudenme con esto (tengo SQL 2000)

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