SQL/Query to return the top two records from panel of data??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan.Aylett@gmail.com

    #1

    SQL/Query to return the top two records from panel of data??

    Hi,

    I have some data in panel format:

    id1, 1990, 100
    id1, 1991, 101
    id1, 1992, 99
    id1, 1993, 103
    id2, 1990, 80
    id2, 1991, 83
    id2, 1992, 78
    id2, 1993, 90
    id3..... etc.

    Is there any way I can -- without re-structuring the data -- write a
    query that will return the top two records from each panel? Similar to
    the max function but taking the top two instead of top one. The
    desired output would be:

    id1, 1993, 103
    id1, 1991, 101
    id2, 1993, 90
    id2, 1991, 83
    id3.... etc.

    Thanks in advance for the help,

    Alan
Working...