How do I find the all records that are the latest from each user, by
user_id? I'm trying to get an :average working but I can't solve it.
This is my find:
How do I find the all records that are the latest from each user, by
user_id? I'm trying to get an :average working but I can't solve it.
This is my find:
What also helps is to read your log, find your select statement, stick that into an editor, edit it, stick it into MySQL, and see what it does. Repeat until it works, then either retrofit it into your .average() statement, or just call count_by_sql on the raw SELECT.
As a style thing, there's no harm in calling a raw SELECT statement from Rails, so long as you don't go basing your whole architecture on it!
What also helps is to read your log, find your select statement, stick
that into
an editor, edit it, stick it into MySQL, and see what it does. Repeat
until it
works, then either retrofit it into your .average() statement, or just
call
count_by_sql on the raw SELECT.
As a style thing, there's no harm in calling a raw SELECT statement from
Rails,
so long as you don't go basing your whole architecture on it!