Skip to content

Instantly share code, notes, and snippets.

@choplin
Created January 7, 2014 06:05
Show Gist options
  • Save choplin/8295245 to your computer and use it in GitHub Desktop.
Save choplin/8295245 to your computer and use it in GitHub Desktop.
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