Codeigniter中的IFNULL(COUNT('id'),0)

Nyx*_*nyx 6 codeigniter

我相信在使用Active Records的Codeigniter中这一行有一个错误,但我似乎无法用IFNULL()和COUNT()来计算第二行的语法

$this->db->select('places.*, category.*')
            ->select('IFNULL(COUNT("places_reviews.place_id"), 0) AS num_reviews')
            ->from('places')
            ->join('category', 'places.category_id = category.category_id')
            ->join('places_reviews', 'places_reviews.place_id = places.id', 'left')
            ->where('places.category_id', $category_id)
            ->group_by('places.id')
            ->limit($limit, $offset)
            ->order_by($sort_by, $sort_order);
Run Code Online (Sandbox Code Playgroud)

Roc*_*mat 17

false在SELECT语句后添加.CodeIgniter试图用反引号来逃避语句,并且不知道如何正确地执行此操作.该false会告诉它不要.

->select('IFNULL(COUNT(`places_reviews.place_id`), 0) AS `num_reviews`', false)
Run Code Online (Sandbox Code Playgroud)

编辑:在COUNT("places_reviews.place_id"),报价应该是反引号.