Created
November 24, 2022 15:22
-
-
Save mshakhomirov/459b68c5f3d1e8284c01e516db1d8dcb 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 top_spenders as ( | |
select 1 as user_id, 100 as total_spend, 11 as reputation_level union all | |
select 2 as user_id, 250 as total_spend, 11 as reputation_level union all | |
select 3 as user_id, 250 as total_spend, 11 as reputation_level union all | |
select 4 as user_id, 300 as total_spend, 11 as reputation_level union all | |
select 11 as user_id, 1000 as total_spend, 22 as reputation_level union all | |
select 22 as user_id, 1500 as total_spend, 22 as reputation_level union all | |
select 33 as user_id, 1500 as total_spend, 22 as reputation_level union all | |
select 44 as user_id, 2500 as total_spend, 22 as reputation_level | |
) | |
select | |
user_id | |
, rank() over(partition by reputation_level order by total_spend desc) as rank | |
, dense_rank() over(partition by reputation_level order by total_spend desc) as dense_rank | |
from | |
top_spenders | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment