My app need a line graph where i am going to show the number of new users joined by the country in last 3 days. i am plotting multiple lines on the same graph. so, i need to show empty value as well.
users table:
+------------+-------------------+----------------------------------------+ |id | First_name |country_id | created_at | +------------+-------------------+-----------------+----------------------+ | 1 | AAA | 3 | 2014-02-23 15:55:55 | | 2 | BBB | 5 | 2014-02-22 15:55:55 | | 3 | CCC | 1 | 2014-02-22 17:55:55 | | 4 | DDD | 2 | 2014-02-22 15:55:55 | | 5 | EEE | 1 | 2014-02-22 16:55:55 | | 6 | FFF | 1 | 2014-02-23 15:55:55 | +------------+-------------------+-----------------+----------------------+
the query:
Select COUNT(users.id) AS count, DATE(users.created_at) AS date , users.country_id
from `users`
where `created_at` >= '2014-02-21' and `created_at` < '2014-02-24' and users.country_id IN(1, 3, 10)
group by `date`, users.country_id
order by `date` asc
Expected output:
+------------+-------------------+------------------ |count | date |country_id | +------------+-------------------+-----------------+ | 0 | 2014-02-21 | 1 | | 0 | 2014-02-21 | 3 | | 0 | 2014-02-21 | 10 | | 2 | 2014-02-22 | 1 | | 0 | 2014-02-22 | 3 | | 0 | 2014-02-22 | 10 | | 1 | 2014-02-23 | 1 | | 1 | 2014-02-23 | 3 | | 0 | 2014-02-23 | 10 | +------------+-------------------+-----------------+
The above query do not return any value if there is no data. How can i print 0 if no data found for a country for a day.