[英]Select All Rows, Group By
While using Codeigniter 3, I'm trying to select all records from table "X" while trying to group them by column "Y" as shown below: 在使用Codeigniter 3时,我试图从表“ X”中选择所有记录,同时尝试按列“ Y”对它们进行分组,如下所示:
$this->db->select();
$this->db->from("X");
$this->db->where(array('is_active' => 1));
$this->db->group_by('Y');
However, this retrieves only one record for each group.... any help would be great! 但是,这只为每个组检索一条记录。...任何帮助都将非常有用! Thanks!
谢谢!
Use the following pattern : 使用以下模式:
$this->db->select('*');
$this->db->from('X');
$this->db->where('is_active', 1);
$this->db->group_by('Y');
$query_result = $this->db->get();
$result = $query_result->result();
return $result;
使用$ this-> db-> get()-> result_array()并将其分配给变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.