Skip to content

POSTGRESQL-COALESCE-FOR-ZERO

实现方案: COALESCE嵌套NULLIF

sql
SELECT company, COALESCE(NULLIF(turnover, 0), revenue) AS revenue FROM company_profile;
SELECT company, COALESCE(NULLIF(turnover, 0), revenue) AS revenue FROM company_profile;

postgresql - Coalesce for zero instead of null - Stack Overflow