SQL - el maximo registro

 
Vista:

el maximo registro

Publicado por mery (6 intervenciones) el 02/08/2005 02:01:51
Hola Foro
Tengo una tabla con valores como el que sigue

ruc,DEPEN_ORIGEN,NUM_PROCESO,CORRELATIVO
20100015871,0021,2131,10
20100015871,0021,2135,2

y son ordenados por DEPEN_ORIGEN,NUM_PROCESO,CORRELATIVO
si el num_origen es igual veo num_proceso como en este caso , como el num_proceso son distintos entonces me quedo con el mayor y ya no veo el correlativo , como podria hallar este registro con un slect o necesito hacer un Store Procedure

si hago
select p.ruc ,max (p.), max(p.NUM_PROCESO),max(p.CORRELATIVO) from padron_sunat_prin1 p
where ruc='20100015871'
group by p.ruc,p.DEPEN_ORIGEN,p.NUM_PROCESO, p.CORRELATIVO

me sale lo de arriba y yo quiero el segundo registro

.....Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:el maximo registro

Publicado por Liliana (426 intervenciones) el 02/08/2005 15:16:27
Hola Mery,
Fijate si es esto lo que necesitás:

create table #test
(ruc char(15), DEPEN_ORIGEN smallint, NUM_PROCESO smallint, CORRELATIVO smallint)
insert #test select '20100015871',0021,2131,10
insert #test select '20100015871',0021,2135,2
insert #test select '20100015871',0022,8888,10
insert #test select '20100015871',0022,9999,2

select ruc, DEPEN_ORIGEN, NUM_PROCESO = max(NUM_PROCESO), CORRELATIVO = max(CORRELATIVO)
from #test
group by ruc, DEPEN_ORIGEN

Saludos, Liliana.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar