Last active
January 20, 2017 18:17
-
-
Save alespouzar/214e645e4630f214f0c61aee56515496 to your computer and use it in GitHub Desktop.
Snowflake workaround for missing WINDOW FRAME in LAST_VALUE function
This file contains 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
CREATE OR REPLACE TABLE "test" ("id" INTEGER, "text" VARCHAR); | |
INSERT INTO "test" ("id", "text") VALUES (1, 'first'), (2, 'second'), (3, NULL), | |
(4, NULL), (5, 'fifth'), (6, NULL), (7, NULL), (8, NULL), (9, 'ninth'); | |
SELECT * FROM "test" ORDER BY "id"; | |
SELECT "id", | |
FIRST_VALUE("text") OVER (PARTITION BY "grp" ORDER BY "id") AS "text" | |
FROM | |
( | |
SELECT | |
"id", | |
"text", | |
SUM(CASE WHEN "text" IS NOT NULL THEN 1 ELSE 0 END) OVER (ORDER BY "id") AS "grp" | |
FROM "test" | |
) AS "subq"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment