How to write SUM(IF(boolean, integer, integer)) col_name in query in postgresql

mysql, postgresql

Solution

have you tried case?

SUM(CASE WHEN id IN (1, 2, 3, 4, 5, 6) THEN 1 ELSE 0 END)

Problem

I am new to Postgresql. I want to write a query like that: ``` SELECT SUM(IF(id in(1,2,3,4,5,6),1,0)) spl_count from tab group by id; ``` But it is not working. It is giving error like that: ``` function if(boolean, integer, integer) does not exist ``` Actually I have tried same kind of query I mean sum(if(boolean, integer, integer)) in mysql. It is working there but not in postgresql. So how will I write that kind of query in postgresql?

Original source