I referred to this question
I am trying to get the top 5 sequence of each id. I am using Sybase Ase 16.0 and i believe Rank/Partition is not supported
My expected output is something like
id sequence
-- --------
1 1
1 2
1 3
1 4
1 5
2 1
2 2
3 1
3 2
3 3
I tried the below, but is not sure i get the output like above in sybase
select sysprocedures.id, sysprocedures.sequence,
(select count('x') from sysprocedures t2 where sysprocedures.id = t2.id and sysprocedures.sequence < t2.sequence) as myrank from sysprocedures;
sysprocedures.sequencenumbering starts with0so we can use this to our advantage in thewhereclause:Running this in the
masterdatabase generates:NOTE: verified against an
ASE 16.0 SP04 PL04instanceAssuming a) the
sysproceduresquery is an attempt at a minimal example and therefore b) the proposed answer does not work with OP's real world data ... OP may want to ask a new question and provide a more realistic set of data and explanation. For example:sequenceisn't always the same number (eg,id=1has amin(sequence)=3,id=7has amin(sequence)=17, etc)sequencesfor a givenid(eg,id=1sequence series is3, 4, 5, 36, 42, 126)