Created
August 12, 2020 01:55
-
-
Save hoganlong/18456ea2f3ff989c34ad636c403bfaf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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