I have a column which contains null values in some of the rows.
I want to do sum of the column values by writing a select statement in sqlite.
How do I write the statement so that it treats null values as 0.
My current sqlite statement: select sum(amount) from table1
gives error as it returns null.
Please help.
You can use ifnull(x,y) or coalesce(x,y,z,…) function. Each of them return the first non-null value from the parameter list from left to right. ifnull has exactly two parameter whereas coalesce has at least two.
select sum(ifnull(amount, 0)) from table1