我有一个查询学生分数表并返回其总分数,年级,注册号和分数排名(位置)的函数。我想编写一个Sql联接,该联接将使用分数表返回的注册号来获取来自学生表的学生姓名,但姓名不会返回,并且我没有收到任何错误。
public function get_subject_result(){
$subjectID = $this->input->get('subjectID');
$termID = $this->input->get('termID');
$sessionID = $this->input->get('sessionID');
//This Query which gave me headache actually ranks the total score and return positions
//$this->db->query("JOIN student ON main.stud_reg = student.reg");
$query = $this->db->query("SELECT (SELECT COUNT(*) + 1
FROM result ref
WHERE ref.total > main.total AND subject_id='".$subjectID."' AND term_id='".$termID."' AND session_id='".$sessionID."') as rank, ca1, ca2, exam,
total, remark, stud_reg, grade, subject_id
FROM result main JOIN student ON main.stud_reg = student.reg WHERE subject_id='".$subjectID."' AND term_id='".$termID."' AND session_id='".$sessionID."'
ORDER BY total DESC");
if ($query->num_rows() > 0) {
return $query->result();
}else{
return false;
}
}