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

Raggruppa per mese e restituisce 0 se i dati non vengono trovati

Non ho provato ma dovrebbe funzionare:

SELECT MONTH(created_at) AS month_num, 
DATE_FORMAT(created_at, '%b') AS month_name, ifnull(count(*),0) AS total_num 
    FROM table WHERE user_id=1384249399168
    GROUP BY MONTH(created_at) ORDER BY created_at DESC