Php 如何找到一个班级的最高平均分

Php 如何找到一个班级的最高平均分,php,mysql,codeigniter,Php,Mysql,Codeigniter,我试图显示一个班级的最高平均分数;然而,我已经和这个查询纠缠了几个小时,似乎无法让它工作 我可以获得要显示的学生平均分数列表,其中包括: public function GetSumAvgftScore($student_id, $session_id, $section_id, $class_id) { $this->db->select_avg('ft_tot_score'); $this->db->where('stu

我试图显示一个班级的最高平均分数;然而,我已经和这个查询纠缠了几个小时,似乎无法让它工作

我可以获得要显示的学生平均分数列表,其中包括:

   public function GetSumAvgftScore($student_id, $session_id, $section_id, $class_id) 
    {
        $this->db->select_avg('ft_tot_score');
        $this->db->where('student_id', $student_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        return $this->db->get('ftscores_primary')->row(); 
    }
然而,当我试图显示最高的平均分数时,我被卡住了。这就是我尝试过的:

  public function GetHighestClassAvg($student_id, $session_id, $section_id, $class_id) 
    {
        $this->db->order_by('ft_tot_score', 'DESC');
        $this->db->select_max(avg('ft_tot_score'));
        $this->db->where('student_id', $student_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        $data = $this->db->get('ftscores_primary')->row(); 
    }
这没有给我任何帮助。

试试这个:

 function GetHighestClassAvg($student_id, $session_id, $section_id, $class_id) 
    {
        $this->db->order_by('ft_tot_score', 'DESC');
        $this->db->select_avg('ft_tot_score');
        $this->db->where('student_id', $student_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        $data = $this->db->get('ftscores_primary')->row(); 
    }

这个
$This->db->where('student\u id',$session\u id)
是您的问题中的一个输入错误,还是您的问题的可能原因?我已经纠正了它,现在我收到了错误
消息:调用未定义的函数avg()
这仍然是学生的平均分数。我想选出最高的平均值。平均值将是相同的数字,学生成绩表中显示的最大值是多少。学生的平均分数将显示在他的工作表上,该班级的最高平均分数也将显示在他的工作表上。在这种情况下,请从给定查询的结果中选择最大值。限制$this->db->LIMIT(1)$query=$this->db->get('my_table')$myRow=$query->row();使用偏移量和限制$query=$this->db->get('mytable',0,1)$myRow=$query->row();不幸的是,它没有给我最高的平均值