Skip to content

Instantly share code, notes, and snippets.

@William9923
Created August 12, 2021 16:29
Show Gist options
  • Save William9923/2b8eaee4528aa9dcab982a0bb2071ad0 to your computer and use it in GitHub Desktop.
Save William9923/2b8eaee4528aa9dcab982a0bb2071ad0 to your computer and use it in GitHub Desktop.
select user_name , customer_zip_code , customer_city , customer_state
from (
SELECT
DISTINCT *,
RANK() over(
PARTITION BY user_name
ORDER BY customer_zip_code DESC, customer_state DESC , customer_city DESC
) as rank
FROM
live.user u
) dedup
where rank = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment