I am googled and stackoverflowed high and low and unable to find any specific solutions to display the 2nd (nth) record for each group.
Consider the following table (order by created_at desc):
----------------------------------------------
bid_id | status | created_at
----------------------------------------------
1 | cancelled | 2015-10-03
1 | awarded | 2015-10-02
1 | pending | 2015-10-01
2 | pending | 2015-10-01
3 | denied | 2015-10-02
3 | pending | 2015-10-01
The result of the result should look like this (grouped by bid_id):
bid_id | status | created_at
----------------------------------------------
1 | awarded | 2014-10-02
3 | pending | 2014-10-01
What is efficient SQL to achieve this? Any advice is appreciated!
source
share