Skip to content

Instantly share code, notes, and snippets.

@judell
Created June 9, 2024 18:21
Show Gist options
  • Save judell/d023341e4f8aa3f73149e11b0e27ba7b to your computer and use it in GitHub Desktop.
Save judell/d023341e4f8aa3f73149e11b0e27ba7b to your computer and use it in GitHub Desktop.
org members using dense_rank
WITH cte AS (
SELECT
org_handle,
user_handle,
status,
ROW_NUMBER() OVER (PARTITION BY org_handle ORDER BY user_handle) AS rn,
DENSE_RANK() OVER (ORDER BY org_handle) AS org_rank
FROM
pipes_organization_member
)
SELECT
CASE
WHEN rn = 1 THEN org_handle
ELSE ''
END AS org_handle,
user_handle,
status
FROM
cte
ORDER BY
org_rank,
rn;
EOQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment