在使用 Codeigniter 3 时,我尝试从表“X”中选择所有记录,同时尝试按列“Y”对它们进行分组,如下所示:
$this->db->select();
$this->db->from("X");
$this->db->where(array('is_active' => 1));
$this->db->group_by('Y');
但是,这只会为每个组检索一条记录......任何帮助都会很棒!谢谢!
最佳答案
使用以下模式:
$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;
关于php - 选择所有行,分组依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40745815/