Qui è la mia query di selezione:Come posso rendere una query MySQL SUM restituita zero anziché null se non ci sono record?
SELECT SUM(rating) AS this_week
FROM table_name
WHERE UNIX_TIMESTAMP(created_at) >= UNIX_TIMESTAMP() - 604800)
che conta fondamentalmente la valutazione di un elemento per l'ultima settimana (604800 è un numero di secondi in 1 settimana).
Il problema è che quando non ci sono righe nella tabella, this_week verrà restituito come NULL. Vorrei che la query restituisse 0 nel caso in cui non ci fossero righe nella tabella. Come farlo?
Grazie, questo ha fatto esattamente quello che mi serviva :) –