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?
你试过案例吗?
SUM(CASE WHEN id IN (1, 2, 3, 4, 5, 6) THEN 1 ELSE 0 END)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.