【问题标题】:CodeIgniter Subquery in Query Builder查询生成器中的 CodeIgniter 子查询
【发布时间】:2018-08-22 04:58:49
【问题描述】:

有没有办法或有人可以将其转换为代码点火器查询构建器。

SELECT result.id, result.name, result.added
FROM (SELECT tbl.id, tbl.name, tbl.date_added
      FROM table tbl
      GROUP BY tbl.id) result
GROUP BY result.date_added

我已经有我的研究(下面的链接)但找不到类似的东西(上面的查询)。 https://www.codeigniter.com/userguide3/database/query_builder.html

https://arjunphp.com/how-to-write-subqueries-in-codeigniter-active-record/

是的,这可以使用存储过程来完成,但我还有另一个原因需要将其实现为查询生成器。

【问题讨论】:

    标签: php codeigniter-3 query-builder


    【解决方案1】:

    试试这个。

    // Sub Query
             $this->db->select('result.id, result.name, result.added')->from('table tbl');
         $subQuery =  $this->db->get_compiled_select();
    
    // Main Query
         $this->db->select('result.id, result.name, result.added')
         ->from('table tbl')
         ->where("id IN ($subQuery)", NULL, FALSE)
         ->get()
         ->result();
    

    【讨论】:

    • 感谢您的回答。我已经阅读了您回答的文章,这是我在我的问题中包含的链接。 arjunphp.com/…
    猜你喜欢
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2021-12-03
    相关资源
    最近更新 更多