duvida de select [aparecer só uma linha]
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
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
Curtidas 0
Respostas
Motta
14/03/2006
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
GOSTEI 0
Rosterne
14/03/2006
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;
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;
GOSTEI 0