Skip to content

Instantly share code, notes, and snippets.

@mshakhomirov
Created November 24, 2022 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshakhomirov/05d0c04c5975207d98552ffd436add8b to your computer and use it in GitHub Desktop.
Save mshakhomirov/05d0c04c5975207d98552ffd436add8b to your computer and use it in GitHub Desktop.
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