Created
October 17, 2017 13:40
-
-
Save anonymous/ef1f5bb79eff2100295430132ceae951 to your computer and use it in GitHub Desktop.
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
WITH d AS | |
( | |
SELECT * | |
FROM atable | |
WHERE date >= CURRENT_TIMESTAMP - INTERVAL '1 YEAR' | |
) | |
SELECT * | |
FROM d | |
UNION ALL | |
SELECT * | |
FROM atable | |
WHERE date < CURRENT_TIMESTAMP - INTERVAL '1 YEAR' | |
ORDER BY date DESC | |
LIMIT GREATEST(0, 50 - (SELECT COUNT(*) FROM d)) ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment