查询代码:
$query = $this->db->query(
'SELECT course.*, AVG(course_review.`rating`) AS `avg_rating`
FROM course
LEFT JOIN course_review ON `course`.`id` = `course_review`.`course_id`
WHERE `course`.`course_category`= ' . $id . '
AND `course`.`approved`= 3
AND `course`.`delete_course` != 1
AND `course`.`unpublish_course` != 1
GROUP BY `course`.`id`
ORDER BY avg_rating DESC');
return $query->result()
由于
答案 0 :(得分:0)
您可以针对您的问题尝试此查询:
<强>查询: - 强>
$query = $this->db->query('SELECT
course.id,
AVG(course_review.rating) AS avg_rating
FROM course
LEFT JOIN course_review
ON course.id = course_review.course_id
WHERE course.course_category = ' . $id . '
AND course.approved = 3
AND course.delete_course != 1
AND course.unpublish_course != 1
GROUP BY course.id
ORDER BY avg_rating DESC');
return $query->result();