【发布时间】:2012-09-12 13:42:50
【问题描述】:
我的网站上有一个特色部分,其中包含三种类型的特色帖子:普通、大和小。目前我正在三个单独的查询中获取这三种类型,如下所示:
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :big).limit(1)
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :small).limit(1)
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :normal).limit(5)
基本上,我正在寻找一个将这三者合二为一并获取 1 个大帖子、1 个小帖子和 5 个普通帖子的查询。
【问题讨论】:
标签: sql ruby-on-rails optimization join