Skip to content

Instantly share code, notes, and snippets.

@hoganlong
Created August 12, 2020 01:55
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 hoganlong/18456ea2f3ff989c34ad636c403bfaf6 to your computer and use it in GitHub Desktop.
Save hoganlong/18456ea2f3ff989c34ad636c403bfaf6 to your computer and use it in GitHub Desktop.
with data(id, dept, age, name) as
(
values
(1, 'A', 60, 'A A' ),
(2, 'A', 70, 'B B' ),
(3, 'A', 80, 'C C' ),
(4, 'A', 90, 'D D' ),
(5, 'A', 100, 'E E' ),
(6, 'B', 10, 'F F' ),
(7, 'B', 20, 'G G' ),
(8, 'B', 30, 'H H' ),
(9, 'B', 40, 'I I' ),
(10, 'B', 50, 'J J' )
)
SELECT DEPT, FIRST(AGE) OVER (PARTITION BY dept ORDER BY NAME DESC) AS CASE ONE,
FIRST(AGE) OVER (PARTITION BY dept ORDER BY NAME DESC RANGE UNBOUNDED PROCEDING UNBOUNDED FOLLOWING) AS CASE TWO
FROM data
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment