Created
November 13, 2020 14:06
-
-
Save Heavyblade/cd3421eae5338dc3ff51c75a27d08dcf to your computer and use it in GitHub Desktop.
holidays.sql
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
SELECT user_id, | |
last_date, | |
spent | |
FROM | |
(SELECT wa.user_id, | |
MAX(wa.created_on) AS last_date | |
FROM ec4u.wfh_answer wa | |
GROUP BY wa.user_id) users | |
LEFT JOIN LATERAL | |
(SELECT count(*) spent | |
FROM generate_series(users.last_date, '2020-11-30'::TIMESTAMP, '1 day'::interval) dd | |
LEFT JOIN ec4u.holiday h ON h.holiday_date = dd | |
WHERE to_char(date_trunc('day', dd)::date, 'day') not in ('saturday ', 'sunday ') | |
AND holiday_date IS NULL ) days ON TRUE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment