php-从Codeigniter Active Record中的子查询中选择

我将如何在Codeigniter ActiveRecord中执行以下查询:-

SELECT *, 

(SELECT 
        image_path
    FROM
        image
    WHERE
        image_table = 'model'
            AND image_table_id = model_id
    GROUP BY image_table_id
    LIMIT 1) AS ModelImg 

FROM

   (SELECT 
      *
   FROM
      vw_newcars
    where offer_table = 'derivative'
    order by offer_order
   ) x

WHERE make_name = 'Fiat'
group by offer_table_id
limit 12

我遇到的问题是如何从Active Record中的子查询中进行选择.

我在文档中没有看到from_select函数或类似的东西.

解决方法:

我通过将from_subquery放入初始的select语句中设法使查询起作用:

$this->db->select("*, 
  (select image_path from image where image_table = 'model' and image_table_id = model_id
  group by image_table_id limit 1) as ModelImg FROM 
  (SELECT * FROM $view where offer_table = 'derivative' order by offer_order) x"); 
上一篇:php-CodeIgniter-无法通过数组进行查看


下一篇:mysql-Codeigniter用相同的列联接