[英]Multiple Select Count SQL queries in Codeigniter Active Record
我喜歡將以下MySQL查詢轉換為Codeigniter Active Record查詢。
以下是MySQL:
select brand_id,name,(select count(*) from items where brand_id = b.brand_id) as itemc, (select count(*) from models where brand_id = b.brand_id) as modelc from brands as b
Codeigniter:
$this->db->limit($perpage,$page);
$query = 'select brand_id,name,(select count(*) from items where brand_id = b.brand_id) as itemc, (select count(*) from models where brand_id = b.brand_id) as modelc from brands as b limit '.$perpage.' offset '.$page.'';
$query = $this->db->query($query);
$query = $query->result();
return $query;
請幫助我將上面的代碼轉換為Codeigniter Active Record。
這是活動記錄中的查詢
$rows = $this->db->select('b.brand_id,b.name')
->select('(select count(*) from items where brand_id = b.brand_id) as itemc',FALSE)
->select('(select count(*) from models where brand_id = b.brand_id) as modelc',FALSE)
->from('brands as b')
->limit($perpage,$page)->get()->result();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.