sql - top 1 date foreach date -


i have structure

table idc (numid,idint, idaffiliate) table glob (idint, idatt) table gratt(idatt, dtromp) table update(idaffiliate, dateupdate) 

making select statement give me :

select     numid,      dateupdate,      dtromp,     idc.idfiliale  idc inner join glob on glob .idint = idc.idint            inner join grat on glob.idatt = grat.idatt             inner join update on update.idaffiliate = idc.idaffiliate numid = 9976666 

will give me :

numid   dtupdate              dtromp            filiale 9976666 01/05/2005            11/07/2006        27 9976666 01/05/2005            03/07/2008        27 9976666 01/05/2005            24/06/2010        27 9976666 01/05/2006            11/07/2006        27 9976666 01/05/2006              03/07/2008      27 9976666 01/05/2006            24/06/2010        27 

i m trying : select close dtupdqte dtromp , inferior it

kindest regards

i have been trying but no solution yet.

you can row_number():

select numid, dateupdate, dtromp, idc.idfiliale (select numid, dateupdate, dtromp, idc.idfiliale,              row_number() on (partition numid, dtromp order dtromp desc) seqnum       idc inner join glob on glob .idint = idc.idint                  inner join grat on glob.idatt = grat.idatt                   inner join update on update.idaffiliate = idc.idaffiliate       numid = 9976666 , dateupdate < dtromp      ) t seqnum = 1; 

Comments