I am attempting to produce multiple results for each value. Postgres
Select count (*) from table_name Where column_id IN(value1, value2, value3)
Looks like the outputs are adding everything together and I'd like the individual results for each value.
I was expecting the output for value 1, value 2, and value 3 not the combined sum, the individual values.
CodePudding user response:
You'll want to use either a GROUP BY
clause
SELECT column_id, count(*)
FROM table_name
WHERE column_id IN (value1, value2, value3)
GROUP BY column_id
or run multiple separate counts
SELECT
count(*) FILTER (WHERE column_id = value1) AS value1_count,
count(*) FILTER (WHERE column_id = value2) AS value2_count,
count(*) FILTER (WHERE column_id = value3) AS value3_count
FROM table_name