1

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.

Cragmorton
  • 153
  • 2
  • 11
  • possible duplicate of [How to fill date gaps in MySQL?](http://stackoverflow.com/questions/1877874/how-to-fill-date-gaps-in-mysql) – Jordan Running Dec 15 '14 at 17:46
  • you can look at http://stackoverflow.com/questions/2157282/generate-days-from-date-range to generate dates – syllabus Dec 16 '14 at 13:45

0 Answers0