I have a query in SQL which sum values and add them as months to a date.
SELECT
FROM_UNIXTIME(S.created) as start_date,
(FROM_UNIXTIME(S.created) + INTERVAL (C.items_left + C.items_given) MONTH)
AS end_date,
FROM table1 S
LEFT JOIN table2 C ON C.id = S.id;
The problem arises when some of these values to sum are null instead of 0 and I am not able to change the source of data.
(FROM_UNIXTIME(S.created) + INTERVAL (C.items_left + C.items_given) MONTH)
AS end_date,
is generating nulls because (C.items_left + C.items_given) is null.
So, the question is, how do I execute this sum so the result is 0 instead of null?