Skip to content

Instantly share code, notes, and snippets.

@mikaelweave
Last active March 15, 2016 17:18
Show Gist options
  • Save mikaelweave/45afc9c6c6626ad6dfed to your computer and use it in GitHub Desktop.
Save mikaelweave/45afc9c6c6626ad6dfed to your computer and use it in GitHub Desktop.
Examples on how to use row_number and rank
SELECT
ROW_NUMBER() OVER (ORDER BY ct_id) AS row_num,
ROW_NUMBER() OVER (PARTITION BY source_id ORDER BY ct_id) AS partitioned_row_num,
RANK() OVER (ORDER BY ct_id) AS row_num,
RANK() OVER (PARTITION BY source_id ORDER BY ct_id) AS partitioned_row_num
FROM
ct_pstor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment