SELECT COALESCE(sum(CASE WHEN myCol THEN 1 ELSE 0 END),0) FROM <table name>
or, as you found out for yourself:
SELECT count(CASE WHEN myCol THEN 1 END) FROM <table name>
More Related Contents:
- Select first row in each GROUP BY group?
- How to concatenate strings of a string field in a PostgreSQL ‘group by’ query?
- How to use RETURNING with ON CONFLICT in PostgreSQL?
- PostgreSQL DISTINCT ON with different ORDER BY
- IN vs ANY operator in PostgreSQL
- Escaping keyword-like column names in Postgres
- Transpose latest rows per user to columns
- Delete duplicate rows (don’t delete all duplicate)
- GROUP BY + CASE statement
- Split column into multiple rows in Postgres
- subquery in FROM must have an alias
- Compute percents from SUM() in the same SELECT sql query
- SQL Between clause with strings columns
- Insert an image in postgresql database
- Perform this hours of operation query in PostgreSQL
- Getting date list in a range in PostgreSQL
- Postgres Dynamic Query Function
- How do I delete a fixed number of rows with sorting in PostgreSQL?
- Does the JDBC spec prevent ‘?’ from being used as an operator (outside of quotes)?
- How to use an ALIAS in a PostgreSQL ORDER BY clause?
- Postgresql Column Not Found, But Shows in Describe
- INSERT COMMAND :: ERROR: column “value” does not exist
- Return multiple columns and rows from a function PostgreSQL instead of record
- Postgres error updating column data
- Check whether string is a date Postgresql
- SQL LIKE condition to check for integer?
- Counting the number of occurrences of a substring within a string in PostgreSQL
- How to use SQL LIKE condition with multiple values in PostgreSQL?
- Why isn’t row level security enabled for Postgres views?
- Is there a postgres CLOSEST operator?