如何通过错误修复MySQL组

时间:2019-04-24 10:43:38

标签: php mysql

使用MySQL Group By时出现问题,您能帮我吗?

错误是:

  

SQLSTATE [42000]:语法错误或访问冲突:1055 SELECT列表的表达式#15不在GROUP BY子句中,并且包含未聚合的列'programku.ms_file.path',该列在功能上不依赖于GROUP BY子句中的列;这与sql_mode = only_full_group_by(SQL:

select `ms_subcategory`.`name` as `subcategory`, `ms_product`.*, `users`.`name` as `users_name`, `ms_file`.`path` from `ms_product` left join `users` on `ms_product`.`users_id` = `users`.`id` left join `ms_subcategory` on `ms_product`.`subcategory_id` = `ms_subcategory`.`id` left join `ms_file` on `ms_file`.`product_id` = `ms_product`.`product_id` where `ms_product`.`status` = A group by `ms_product`.`product_id` order by `ms_product`.`created_at` desc limit 4 offset 0)

查询:

SELECT   ms_product.*,
         ms_file.path,
         users.name as users_name,
         ms_subcategory.name as subcategory
FROM     ms_product 
   LEFT JOIN users ON
         users.id = ms_product.users_id
   LEFT JOIN ms_subcategory ON
         ms_subcategory.id = ms_product.subcategory_id
   LEFT JOIN ms_file ON
         ms_file.product_id = ms_product.product_id
WHERE    ms_product.status = "A" 
group by ms_product.product_id, ms_file.product_id 
order by ms_product.created_at desc 
LIMIT 4

0 个答案:

没有答案