php - 选择所有行,分组依据

标签 php mysql codeigniter group-by

在使用 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/

相关文章:

php - Codeigniter 事件记录,用于简单查询

javascript - PHP 的 sprintf 函数的 JavaScript 等价物是什么?

php - Wordpress:使用函数 get_post_field() 获取帖子内容时,简码不起作用

php - 日期与 Doctrine2 和 Symfony2 的交集

php - 如果另一个表具有匹配的字段值,如何更新数据库表的 1 个或 2 个字段?

php - 在 PHP MYSQL 中更新

php - 将表单数据插入一张表,然后将特定表单数据插入表2并更新枚举值?

MySQL 选择多个值并添加到一列

php - Codeigniter - 日期格式 - 表单验证

php - 单击正确答案时如何更改按钮的颜色?它在 PHP 中进行了测试。 (代码点火器)