Taha Hussein
Taha Hussein

Reputation: 19

count_at_date using Ruby on rails

How to implement method count_at_date that returns the number of items that were created before a specific date Parameters: date: the date that we need to count at items: an array of items dumped from the DB. Each item consists of: id: an auto increment identifier title: the item's title created_at: timestamp at the time of creation Notes:All the transactions on that table are insertions (no deletions)The array will contain hundreds of millions of elements, hence you need to make sure that the implementation is the most efficient.The implementation should be in Ruby on Rails.

Upvotes: 0

Views: 40

Answers (2)

Raj
Raj

Reputation: 66

day = Policy.where(next_due_date:Date.today .. Date.today + 7,).count

Try to this

Upvotes: 0

A. Colonna
A. Colonna

Reputation: 872

Why you don't do the count in mysql with a query like this :

SELECT count(id) as count_at_date from YourTable Where created_at < YourSpecificDate

Upvotes: 1

Related Questions