SQL Tutorial – Aggregates columns which has NULL values.

Spread the love

You want to perform an aggregation on a column but this column contains some Null values. And as we know Aggregation functions ignores the NULL values when doing calculations. In the below table you can see that we have one null values and our goal is to include some this null value in our aggregation.

Solution –

To include NULL values in aggregations, we can use the COALESCE function which converts NULL values to zero.

SELECT
    AVG(COALESCE(christmas_spending, 0)) as avg_spending
FROM
    actors_info

Rating: 1 out of 5.

Leave a Reply