gpt4 book ai didi

php - MySQL 5.0.12 - 列表不在 GROUP BY 子句中并且包含非聚合列?

转载 作者:行者123 更新时间:2023-11-29 07:13:27 25 4
gpt4 key购买 nike

为什么我在 mysqlnd 5.0.12-dev 上出现以下错误:

1055 - Expression #29 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_name.p2.url' which is not

functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

查询:

SELECT p.* , 
p2.article_id AS parent_id ,
p2.url AS parent_url ,
p3.article_id AS parent_parent_id ,
p3.url AS parent_parent_url ,
p3.title AS parent_parent_title

FROM article AS p
LEFT JOIN article AS p2
ON p2.article_id = p.parent_id
AND p.article_id <> p2.article_id

LEFT JOIN article AS p3
ON p3.article_id = p2.parent_id
AND p2.article_id <> p3.article_id

WHERE p.url = 'contact'
AND p.type = 'page'
AND p.hide = '0'
GROUP BY p.article_id
ORDER BY p.backdated_on DESC

该查询在 mysqlnd 5.0.11-dev正常工作。

有什么想法吗?

最佳答案

看来您的 group by 子句仅包含 p.article_id而您的选择有

p.* , 
p2.article_id AS parent_id ,
p2.url AS parent_url ,
p3.article_id AS parent_parent_id ,
p3.url AS parent_parent_url ,
p3.title AS parent_parent_title

要么将所有选择查询列包含在 group by 中,要么将它们包装在聚合函数中,例如 sum()、count()、max() 等。您实际上想从这个查询中得到什么?

关于php - MySQL 5.0.12 - 列表不在 GROUP BY 子句中并且包含非聚合列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com