Skip to content

Instantly share code, notes, and snippets.

@shaneis
Created April 19, 2018 13:02
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 shaneis/e5a2ad53589715c978015d8916492137 to your computer and use it in GitHub Desktop.
Save shaneis/e5a2ad53589715c978015d8916492137 to your computer and use it in GitHub Desktop.
One method of actually using a Windows Function in a WHERE clause
WITH MahQuery AS (
SELECT DummyId,
PartitionId,
ROW_NUMBER() OVER (PARTITION BY PartitionId ORDER BY DummyId DESC) AS LastN
FROM dbo.DummyTable
)
SELECT DummyId,
PartitionId,
LastN
FROM MahQuery
WHERE LastN <= 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment