我在旧代码中设置了这个 sql 语句,并希望将其移至活动记录,我分阶段解决的问题是如何执行
SELECT news_items.id FROM
(SELECT news_items.* FROM news_items
JOIN feeds ON feeds.id=news_items.feed
LEFT JOIN news_item_country ON news_item_country.id=news_items.country
WHERE news_items.id=30758
ORDER BY date_item DESC )
AS news_items
GROUP BY news_items.id
ORDER BY date_item DESC
尝试使用 Active Record 执行此操作,首先我创建了进入选择内部的选择,至少这是我认为需要完成的。
$news_items = $this->db->select('default_news_items.*')
->from('default_news_items ')
->join('default_feeds','default_feeds.id=default_news_items.feed')
->join('default_news_item_country','default_news_item_country.id=default_news_items.country','left')
->join('default_news_item_options','default_news_item_options.id=default_news_items.options','left')
->where($where)
->order_by('date_item DESC')
->limit($limit)
->get();
接下来,我创建实际的选择并引用 from 中的另一个选择
if ($query = $this->db->select("
news_items.id,
->from($news_items)
->group_by('news_items.id')
->get()) {
它没有用,所以我问是否有人有这方面的经验以及如何去做?