Codeigniter 3.1.7带查询生成器的Concat子查询

时间:2018-03-29 09:23:00

标签: php sql codeigniter subquery concat

我想像这样进行查询

try:
        print custom_field.split("name",1)[2]
except :
        print("Skipping ..")

我确实喜欢这个,但它仍然失败

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' 

如何解决这个问题

1 个答案:

答案 0 :(得分:0)

试试这个

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