为什么这段代码不能在CodeIgniter中运行?

时间:2018-01-31 09:30:32

标签: mysql codeigniter

查询代码:

$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()

由于

1 个答案:

答案 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();