Fórum duvida de select [aparecer só uma linha] #28379

14/03/2006

0

eu quero que nesse select apareça soh o primeiro caso ou sejaa maior data.[a primeira linha]
Select Max(DT_VALIDA), VL_COMIRP, VL_COMIVE from AVTABCOM
where CD_EMPRES = 1
and CD_VENDED = 2
and CD_CANVEN = 1
and CD_LINHA = 1
and CD_CLASSE = 1
and CD_TIPPRO = 1
and CH_PRODUT = ´5456646666666´
group by VL_COMIRP, VL_COMIVE
having Max(DT_VALIDA) > Current_Date


Gabrielherdt

Gabrielherdt

Responder

Posts

14/03/2006

Motta

Select VL_COMIRP, VL_COMIVE from AVTABCOM 
where CD_EMPRES = 1 
and CD_VENDED = 2 
and CD_CANVEN = 1 
and CD_LINHA = 1 
and CD_CLASSE = 1 
and CD_TIPPRO = 1 
and CH_PRODUT = ´5456646666666´ 
and DT_VALIDA = (Select Max(DT_VALIDA
                             from AVTABCOM a2
                             where CD_EMPRES = 1 
                             and CD_VENDED = 2 
                             and CD_CANVEN = 1 
                             and CD_LINHA = 1 
                             and CD_CLASSE = 1 
                             and CD_TIPPRO = 1 
                             and CH_PRODUT = ´5456646666666´ )


quando vc agrupa por valor, vai pegar a mais data daquele valor


Responder

Gostei + 0

14/03/2006

Rosterne

Utilize o rownum:

Select Max(DT_VALIDA), VL_COMIRP, VL_COMIVE from AVTABCOM
where CD_EMPRES = 1
and CD_VENDED = 2
and CD_CANVEN = 1
and CD_LINHA = 1
and CD_CLASSE = 1
and CD_TIPPRO = 1
and CH_PRODUT = ´5456646666666´
AND ROWNUM = 1
group by VL_COMIRP, VL_COMIVE
having Max(DT_VALIDA) > Current_Date
ORDER BY 1 DESC;


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar