Last active
September 9, 2016 02:28
-
-
Save jgomo3/9bd3acafba4d8123deb600e0a04ce6a2 to your computer and use it in GitHub Desktop.
Example of hypotetical FIRST, SECOND and NTH Agregate Function
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
CREATE TEMPORARY TABLE object_with_cases | |
( | |
id int, | |
case int | |
); | |
INSERT INTO object_with_cases | |
(id, case) | |
VALUES | |
(3, 1) | |
(1, 2) | |
(2, 5) | |
(1, 6) | |
(2, 4) | |
(3, 3) | |
(1, 4) | |
; | |
SELECT | |
id | |
, FIRST(case) AS FST | |
, SECOND(case) AS SND | |
, NTH(3, case) AS TRD | |
FROM object_with_cases | |
GROUP BY id | |
ORDER BY case | |
; | |
-- OUTPUT | |
-- | id | FST | SND | TRD | | |
-- | 1 | 2 | 4 | 6 | | |
-- | 2 | 4 | 5 | NULL | | |
-- | 3 | 1 | 3 | NULL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment