Mysql
 sql >> Database >  >> RDS >> Mysql

genera righe vuote anche se vuote tra 2 date

Prova con coalesce funzione che restituirà '0' se sum(orders.amount) è nullo per un mese specifico:

select COALESCE(sum(o.amount), 0) as amount, o.completed_at 
from orders o 
where date(o.completed_at) between '2011/10/01' and '2012/03/06' 
group by year(o.completed_at), month(o.completed_at) order by o.completed_at