简体   繁体   中英

Codeigniter 3.1.7 Concat Subquery with Query Builder

I want to make a query like this

SELECT `product`.`id`, 
       `product`.`slug`, 
       `product`.`name`, 
       `product`.`images`, 
       `product`.`description`, 
       `product`.`price`, 
       (SELECT Group_concat(model) 
        FROM   vehicle 
        WHERE  vehicle.`product_id` LIKE '%`product`.`id`%' escape '!') AS model 
FROM   `product` 
       JOIN `product_category` 
         ON `product_category`.`id` = `product`.`product_category_id` 
       JOIN `product_category_detail` 
         ON `product_category_detail`.`id` = 
            `product`.`product_category_detail_id` 
WHERE  `product_category_detail`.`slug` = 'convensional' 

and I do like this, but it still fails

$this->db->select('qproduct.id, product.slug, product.name, product.images, product.description, product.price')
                ->from('product')
                ->join('product_category', 'product_category.id = product.product_category_id')
                ->join('product_category_detail', 'product_category_detail.id = product.product_category_detail_id')
                ->where('product_category_detail.slug', $detail_category)
                ->subquery->start_subquery('select')->select('GROUP_CONCAT(model)')->from('vehicle')->like('product_id', $id, 'both')->end_subquery('vehicle')
                ->get()->result();

how would the solution of this problem

尝试这个

$this->db->select("product.id, product.slug, product.name, product.images, product.description, product.price, (SELECT Group_concat(model) FROM vehicle WHERE vehicle.product_id LIKE '%product.id%' escape '!') AS model ",false) ->from("product") ->join("product_category "," product_category.id = product.product_category_id ","inner") ->join("product_category_detail "," product_category_detail.id = product.product_category_detail_id ","inner") ->where("product_category_detail.slug = 'convensional'",false,false) ->get()->result();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM