Rails 3 ActiveRecord 临时表
如何在 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
我尝试过做类似的事情
create_table (:average_user_total_time), :temporary=> true do |t|
end
,但不确定如何准确使用它。我需要在我的应用程序中使用它,而不是在迁移中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢安德鲁,我最终采用了以下建议。
http://richtextblog.blogspot.com/2007/09 /mysql-temporary-tables-and-rails.html
Thanks Andrew, I ended up using the following advice.
http://richtextblog.blogspot.com/2007/09/mysql-temporary-tables-and-rails.html