SQL/Query to retrieve top two records from a panel of data?

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

    SQL/Query to retrieve top two records from a panel of data?

    Hi,

    I have a panel of data organised as follows:

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

    Is there any way to -- without re-structuring the data -- write a
    query that will return the top two records based on the third column?
    Like the max function but for the top two instead of top one. The
    desired output would be:

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

    Thanks in advance for your time,

    Alan
Working...