ayuda con query

28/07/2006 - 18:24 por Matias Espinoza | Informe spam
Estimados, si alguno fuera tan amable. Tengo en siguiente duda
tengo los siguientes datos

TIPO|R|CANTIDA|VALOR
1 | 1 | 2 |300
1 | 2 |4 |400
y necesito que la consulta me retorne lo siguiente
tipo|catidad1|cantidad2|monto1|monto2
1 |2 |4 |300 |400

si alguien me podria orientar de lo agradeceria

Preguntas similare

Leer las respuestas

#1 Isaias
28/07/2006 - 19:04 | Informe spam
Matias

¿Son solamente 2 registros?
Saludos
IIslas


"Matias Espinoza" wrote:

Mostrar la cita
#2 Alejandro Mesa
28/07/2006 - 19:09 | Informe spam
Trata:

create table dbo.t1 (
c1 int,
c2 int,
c3 int,
c4 int
)
go

insert into dbo.t1 values(1, 1, 2, 300)
insert into dbo.t1 values(1, 2, 4, 400)
insert into dbo.t1 values(2, 3, 12, 1300)
insert into dbo.t1 values(2, 4, 14, 1400)
go

select
c1,
max(case when rank = 1 then c3 end) as c3_1,
max(case when rank = 2 then c3 end) as c3_2,
max(case when rank = 1 then c4 end) as c4_1,
max(case when rank = 2 then c4 end) as c4_2
from
(
select
a.c1, count(*) as rank, a.c3, a.c4
from
dbo.t1 as a
inner join
dbo.t1 as b
on a.c1 = b.c1
and a.c2 >= b.c2
group by
a.c1, a.c3, a.c4
) as t2
group by
c1
go

drop table dbo.t1
go


- SQL Server 2000

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

- SQL Server 2005

Using PIVOT and UNPIVOT
http://msdn2.microsoft.com/en-us/li...77410.aspx

- Interesante articulo escrito por Miguel Egea, un gran colaborador de este
grupo.

Una consulta interesante escrita para SQL Server 2000 y SQL Server 2005
http://www.configuracionesintegrale...articulo22


AMB


"Matias Espinoza" wrote:

Mostrar la cita
#3 Isaias
29/07/2006 - 00:33 | Informe spam
Hola Alex

¿Como se comportaria con 10, 000 registros?, solo por decir una cantidad de
registros.
Saludos
IIslas


"Alejandro Mesa" wrote:

Mostrar la cita
#4 Matias Espinoza
31/07/2006 - 16:13 | Informe spam
siempre son dos registros por Tipo
"Isaias" wrote in message
news:
Mostrar la cita
Ads by Google
Search Busqueda sugerida