In my rails application I have a following SQL:
query_results = User.find_by_sql("
SELECT DATE(created_at), COUNT(*)
FROM users
WHERE DATE(created_at) > '#{date_from}' AND DATE(created_at) < '#{date_to}'
GROUP BY DATE(created_at);
")
And then i create an array:
query_results.each do |r|
self.labels.push r.attributes.values[0]
self.result_data[0].push r.attributes.values[1]
end
I want to create a chart with users which registered each day between 'date_from' and 'date_to'. But the data only contains days which got a user registered. How to add 0 to count column on each other day. Is it possible to do that in SQL or some ruby loop could work here? Thanks.