-- name: ReadySLI :one WITH clock AS (SELECT clock_timestamp() AS now), cohort AS ( SELECT a.accepted_at,a.first_ready_at,c.now FROM attachments a CROSS JOIN clock c WHERE a.accepted_at>c.now-interval '310 seconds' AND a.accepted_at<=c.now-interval '10 seconds' ) SELECT count(*) FILTER(WHERE accepted_at>now-interval '20 seconds')::bigint AS matured10, count(*) FILTER(WHERE accepted_at>now-interval '20 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely10, count(*) FILTER(WHERE accepted_at>now-interval '40 seconds')::bigint AS matured30, count(*) FILTER(WHERE accepted_at>now-interval '40 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely30, count(*)::bigint AS matured300, count(*) FILTER(WHERE first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely300 FROM cohort;