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?
have you tried case?
SUM(CASE WHEN id IN (1, 2, 3, 4, 5, 6) THEN 1 ELSE 0 END)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With