多列上的MySQL分组,codeigniter

多列上的MySQL分组,codeigniter,mysql,codeigniter,group-by,distinct,group-concat,Mysql,Codeigniter,Group By,Distinct,Group Concat,我知道这个标题听起来像是一个常见的问题,但我在这里四处看看,似乎找不到和我一样的问题(答案) 这就是我的情况:我有三个表(主要标准、问题和结果)。。。有多个主要标准,一个主要标准有多个问题。表格结果包含所有用户对这些问题的答案。。使用此代码: $this->db->simple_query('set session group_concat_max_len=1000000'); $this->db->select('*, GROUP_CONCAT(CONCAT("

我知道这个标题听起来像是一个常见的问题,但我在这里四处看看,似乎找不到和我一样的问题(答案)

这就是我的情况:我有三个表(主要标准、问题和结果)。。。有多个主要标准,一个主要标准有多个问题。表格结果包含所有用户对这些问题的答案。。使用此代码:

$this->db->simple_query('set session group_concat_max_len=1000000');
    $this->db->select('*, GROUP_CONCAT(CONCAT("<tr><td>", eq_question, "</td><td id=fix>", r_value) SEPARATOR "</td></tr>") as quesrate', false);
    $this->db->from('evaluation_result');
    $this->db->join('evaluation_question', 'evaluation_question.eq_ai=evaluation_result.er_eq_ai', left);
    $this->db->join('evaluation_major_criteria', 'evaluation_major_criteria.emc_ai=evaluation_question.eq_emc_ai', left);
    $this->db->join('rating', 'rating.r_ai=evaluation_result.er_rate', left);
    $this->db->where('er_il_ai', $inst);
    $this->db->where('er_ay_ai', $aca);
    $this->db->where('er_sem_ai', $sem);
    $this->db->where('er_et_ai', $evaltype);
    $this->db->order_by('emc_code', 'asc');
    $this->db->group_by('emc_code', 'asc');
    $query=$this->db->get();

它按问题分组。现在我有两个查询,一个按主要标准分组,另一个按问题分组。我想我必须把它们结合起来?但是idk怎么做。

您可以只做$this->db->group_by('emc_代码,asc');让我知道这是否有效,但我已经有了?我已经在分组了。你已经给了2个字符串作为参数,应该发送1个字符串,包含两个用逗号分隔的列名。而且也可能是按顺序排列的。不起作用。它所做的只是返回更多重复的行
$this->db->select('*', false);
    $this->db->from('evaluation_result');
    $this->db->join('evaluation_question', 'evaluation_question.eq_ai=evaluation_result.er_eq_ai', left);
    $this->db->join('evaluation_major_criteria', 'evaluation_major_criteria.emc_ai=evaluation_question.eq_emc_ai', left);
    $this->db->join('rating', 'rating.r_ai=evaluation_result.er_rate', left);
    $this->db->where('er_il_ai', $inst);
    $this->db->where('er_ay_ai', $aca);
    $this->db->where('er_sem_ai', $sem);
    $this->db->where('er_et_ai', $evaltype);
    $this->db->where('eq_s_ai', 2);
    $this->db->order_by('emc_code', 'asc');
    $this->db->group_by('eq_ai');
    $query=$this->db->get();