Reputation: 83
my column look like this:
delta
delta
alpha
alpha
alpha
gamma
gamma
gamma
I'd like to group it and order. So it will result with:
1. alpha
2. delta
3. gamma
And that's still easy. Now, the point is to tell SQL "Show me the second group", not knowing what data we will actually have there. In other words - not naming the group, just by a number. Any idea?
Upvotes: 2
Views: 83
Reputation: 36483
You can use the row_number()
analytic function for that:
select your_col
from (select your_col,
row_number() over (order by your_col) as rn
from your_table
group by your_col)
where rn = 2
Upvotes: 1