4

How do I do the following in Rails 3?

CREATE TEMPORARY TABLE average_user_total_time 
  (SELECT SUM(time) AS time_taken 
        FROM scores 
        WHERE created_at >= '2010-10-10' 
                and created_at <= '2010-11-11' 
        GROUP BY user_id);

SELECT COUNT(*) from average_user_total_time WHERE time_taken > 60 and time_taken < 600

I have tried to do something like

create_table (:average_user_total_time), :temporary=> true do |t|

end

but not sure how to use it exactly. I need to use it within my app and not in a migration.

1
  • Perhaps you should just use raw SQL. Commented Mar 24, 2011 at 0:33

1 Answer 1

6

Thanks Andrew, I ended up using the following advice.

http://richtextblog.blogspot.com/2007/09/mysql-temporary-tables-and-rails.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.