Created
January 7, 2014 06:05
-
-
Save choplin/8295245 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
CREATE TABLE todesking (created_at text, status int); | |
INSERT INTO todesking VALUES | |
('01-01', 0), | |
('01-02', 0), | |
('01-03', 1), | |
('01-04', 0) | |
; | |
SELECT | |
count(CASE WHEN same_as_first_row THEN 1 END) | |
FROM ( | |
SELECT | |
created_at, | |
status, | |
bool_and(status = 0) OVER (ORDER BY created_at ROWS UNBOUNDED PRECEDING) AS same_as_first_row | |
FROM | |
todesking | |
) t | |
; | |
count | |
------- | |
2 | |
(1 row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment