[Info: Ubuntu 14.02, ruby 2.2.3p110, Rails 4.2.1]
I need a rake task to fetch the average inserts per hour from the DB (SQLite).
I was trying to do something like:
namespace :db do
desc "Fetch average inserts per hour and user with the most tweets db."
task results: :environment do
tweet = Tweet.group('date(created_at)').group('hour(created_at)').average()
puts "#{tweet}"
end
end
But this throw me this exception
ActiveRecord::StatementInvalid: SQLite3::SQLException: misuse of aggregate function count(): SELECT AVG(count(*)) AS average_count_all, date(created_at) AS date_created_at, hour(created_at) AS hour_created_at FROM "tweet" GROUP BY date(created_at), hour(created_at)
Is there a way to get this average per hour using ActiveRecord?
Aucun commentaire:
Enregistrer un commentaire