Skip to content
Advertisement

Getting unique record based on max conditions including null values

I need to get back one record of a player’s (Rank A players only) most recent win date (some win dates are null but we need to include them) but picking only the last place of their most recent game session. So basically in that order: get their max win_date (if null, still include them) > from there grab their max place > and from there, pick only their max game_session_id.

Table players:

Expected Output:

My (wrong) code:

Advertisement

Answer

Use ROW_NUMBER with an approriate partition:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement