「PostgreSQL入門」SUM(CASE WHEN)で条件付きで集計するサンプル
SQL構文
SELECT SUM(CASE WHEN ID >=21 THEN 1 ELSE 0 END ) AS 'COLA’,
SUM(CASE WHEN ID <=20 THEN 1 ELSE 0 END) AS 'COLB’
FROM DSTU_TBL
Coding Changes the World
SQL構文
SELECT SUM(CASE WHEN ID >=21 THEN 1 ELSE 0 END ) AS 'COLA’,
SUM(CASE WHEN ID <=20 THEN 1 ELSE 0 END) AS 'COLB’
FROM DSTU_TBL