Hi,
I am executing this query:
==== @monthly_data = ReviewRating.group("date_format(insertdate,
''%Y/%m''),
type").count(:conditions => {:insertdate =>
''2011-01-01''..''2099-01-01''})
(12.7ms) SELECT COUNT(*) AS count_all, date_format(insertdate,
''%Y/%m''), type AS date_format_insertdate_y_m_type FROM
`tc_reviews_rating` WHERE (rev_user_id != 0) AND
(`tc_reviews_rating`.`insertdate` BETWEEN ''2011-01-01'' AND
''2099-01-01'')
GROUP BY date_format(insertdate, ''%Y/%m''), type
=> {1=>477, 2=>26}
====
where as if I execute the SQL directly, I get the correct data.
What am I doing incorrect? Thanks in advance for the help.
Pradeep
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-07 11:41 UTC
Re: Not getting accurate data on multiple field group
On Thursday, December 6, 2012 11:59:54 AM UTC, Ruby-Forum.com User wrote:> > > ===== > @monthly_data = ReviewRating.group("date_format(insertdate, ''%Y/%m''), > type").count(:conditions => {:insertdate => ''2011-01-01''..''2099-01-01''}) > > When you use the string form of group, rails doesn''t look into the stringto see that you are grouping on 2 different things. I''d try group("date_format(insertdate, ''%Y/%m'')", "type") Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aP_c557v-2cJ. For more options, visit https://groups.google.com/groups/opt_out.