Created
March 16, 2018 11:46
-
-
Save barsbek/da6ef36e165a86e7025deae2c2048571 to your computer and use it in GitHub Desktop.
postgresql: count with condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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