Created
November 24, 2022 15:20
-
-
Save mshakhomirov/05d0c04c5975207d98552ffd436add8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with reputation_data as ( | |
select | |
1 as user_id | |
, 100 as reputation | |
, 1 as reputation_level | |
, timestamp_sub(current_timestamp(), interval 3 hour) as ts | |
union all | |
select | |
1 as user_id | |
, 101 as reputation | |
, 1 as reputation_level | |
, timestamp_sub(current_timestamp(), interval 2 hour) | |
union all | |
select | |
1 as user_id | |
, 200 as reputation | |
, 2 as reputation_level | |
, timestamp_sub(current_timestamp(), interval 1 hour) | |
) | |
select * | |
from reputation_data a | |
qualify row_number() over (partition by a.user_id order by a.ts desc) = 1 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment