Skip to content

Instantly share code, notes, and snippets.

@alexmchale
Created March 3, 2017 20:36
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 alexmchale/3172ad02df31b0c0e78fdafcbd511f1e to your computer and use it in GitHub Desktop.
Save alexmchale/3172ad02df31b0c0e78fdafcbd511f1e to your computer and use it in GitHub Desktop.
SELECT COUNT(1) FROM (
SELECT s_stats.id
FROM s_stats
LEFT JOIN s_organizations ON s_stats.organization_id = s_organizations.id
WHERE stats_purged_sents IS NULL
AND (
(
( ( s_organizations.permissions -> 'quota_mode' ) is not distinct from 'no_limit' )
OR
( ( s_organizations.permissions -> 'quota_limit' ) is distinct from '1' )
)
OR
(
s_organizations.deleted_at IS NULL
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment