# ActiveRecord finder using :group?

**URL:** <https://www.ruby-forum.com/t/activerecord-finder-using-group/174718>\
**Category:** Rails\
**Created:** [August 31, 2009, 10:40pm UTC](https://www.ruby-forum.com/t/activerecord-finder-using-group/174718 "2009-08-31T22:40:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [August 31, 2009, 10:40pm UTC](https://www.ruby-forum.com/t/activerecord-finder-using-group/174718/1 "2009-08-31T22:40:59Z")

</div>

I’m trying to gather and display some simple statistical data. I want  
to display the number of Products created over the last month, grouped  
by the day they were created. Am I on the right track as far as the  
ActiveRecord finder and also how would I iterate over the results in  
the view to spit out the date and the count of products for that day?  
Thanks for any help.

# example sql that returns count and date, grouped by the date

SELECT count(\*) as total, created\_at as date FROM products GROUP BY  
date(created\_at) HAVING created\_at \>= ‘2009-07-31’ and created\_at \<=  
‘2009-08-31’;

# AR finder?

@created\_products = Product.find(:all, :group =\> “date  
(created\_at)”, :having =\> [“created\_at \>= ?”, 1.month.ago])

# view code?

- Date : Total

---

<div class="post-metadata">

**Author:** ![coolmenu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eada6e/32.png) [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Post date:** [August 31, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/activerecord-finder-using-group/174718/2 "2009-08-31T22:49:11Z")

</div>

On Aug 31, 9:39 pm, JL Smith [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to gather and display some simple statistical data. I want  
> to display the number of Products created over the last month, grouped  
> by the day they were created. Am I on the right track as far as the  
> ActiveRecord finder and also how would I iterate over the results in  
> the view to spit out the date and the count of products for that day?  
> Thanks for any help.

If you want to count things you’re better off using count - find  
fundamentally wants to return model objects.

Fred
