簡體   English   中英

查詢生成器中的CodeIgniter子查詢

[英]CodeIgniter Subquery in Query Builder

有沒有辦法或有人可以將其轉換為代碼點火器查詢生成器。

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/

是的,這可以使用存儲過程來完成,但是我還有另一個原因需要將其作為查詢生成器來實現。

試試這個。

// 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM