Skip to content

Instantly share code, notes, and snippets.

@barsbek
Created March 16, 2018 11:46
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 barsbek/da6ef36e165a86e7025deae2c2048571 to your computer and use it in GitHub Desktop.
Save barsbek/da6ef36e165a86e7025deae2c2048571 to your computer and use it in GitHub Desktop.
postgresql: count with condition
select count(case when some_col>10 then 1 end) as some_alias;
select count(*) filter(where some_col>10) as some_alias;
-- same can be applied to any aggregation function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment