Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nuria
Created September 23, 2022 16:31
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 nuria/08949769aba66df9ded9bd899425f95e to your computer and use it in GitHub Desktop.
Save nuria/08949769aba66df9ded9bd899425f95e to your computer and use it in GitHub Desktop.
common window function gotcha
select *,
case
when confirmed_at is not null and price_dollars > 0
then row_number() over (
partition by user_id, price_dollars > 0
order by confirmed_at
)
else null
end as user_enroll_rank,
case
when confirmed_at is not null and price_dollars > 0
then row_number() over (
partition by learner_id, price_dollars > 0
order by confirmed_at
)
else null
end as learner_enroll_rank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment