The COALESCE
expression allows for user-specified NULL-handling. It is often used to fill in missing values in dirty data.
COALESCE(a, b, c, x, y, z)
COALESCE
expression to evaluate records for multiple values and return the first non-NULL value encountered, in the order specified. The following requirements apply:
COALESCE
.COALESCE
must all be of the same type, with the exception integers with doubles (in this case, integers are promoted to doubles).COALESCE
does not support multi-assign attributes.AVG(COALESCE(Price, 0))
COALESCE
can also be used without aggregation, for example:
SELECT COALESCE(Price, 0) AS price_or_zero WHERE ...