I have the following 2 records:
| key | start_dt | end_dt | id | status |
|---|---|---|---|---|
| 12 | 2020-8-12 | 2300-01-01 | 1 | active |
| 12 | 1998-9-23 | 2014-9-23 | 2 | active |
This is the row_number() function I currently have:
row_number() over (partition by id order by status, end_dt desc) rnk
I want to know what I need to add to the above row_number() function so that only the top record is showing:
| key | start_dt | end_dt | id | status |
|---|---|---|---|---|
| 12 | 2020-8-12 | 2300-01-01 | 1 | active |
Here's how I would do it for SQL Server. For BigQuery, your syntax will differ a little but I'm sure the structure will be the same.