Skip to content

Instantly share code, notes, and snippets.

@mcdee
Created September 1, 2016 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcdee/f46612adaff3a9409eb4fae293937aff to your computer and use it in GitHub Desktop.
Save mcdee/f46612adaff3a9409eb4fae293937aff to your computer and use it in GitHub Desktop.
SELECT lab_name, COUNT(*)
FROM (
SELECT (record ->> 'scientist_id')::BIGINT AS scientist_id
FROM measurements
WHERE
record @> '{"value_1":0}' AND
record @> '{"value_2":0}' AND
record @> '{"value_3":0}'
) m
JOIN scientist_labs AS s
ON (m.scientist_id = s.scientist_id)
GROUP BY lab_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment