Question: I have a table with below mentioned columns. I want to fetch the previous status of customer. Once customer id can have multiple entries

```
Customer_id   status     start_date    end_date   Active
1             Member      01-JAN-18    04-FEB-18   N
1             Explorist   05-FEB-18    30-APR-18   N
1             Globalist   01-MAY-18    31-DEC-99   Y

```

Desired output

```
Customer _id     Previous_status   end_date
1                Explorist          30-APR-18

```

Answer: 
Please try below query using QUALIFY keyword and ROW\_NUMBER():

```
SELECT a.* from table a 
QUALIFY ROW_NUMBER OVER(PARTITION BY customer_id order by start_date desc) = 2

```
Consider this question: [Select Nth Row From A Table In Oracle](https://stackoverflow.com/questions/4509167/select-nth-row-from-a-table-in-oracle)

In your case, that would be:

```
select * from (select a.*, rownum rnum from (select * from <your table name> 
order by <start_date or end_date> desc) a where rownum <= 2) where rnum >= 2;

```