我不是DBA,我继承了此查询,但我不确定为什么我会收到sql_mode=only_full_group_by
错误。特别是因为错误是在谈论result.fullURL
而我在查询中没有看到。有人可以向我解释一下吗?
查询
SELECT *
FROM (
SELECT content.*, content.navigationOrder AS sortOrder
FROM LB_Content AS content
INNER JOIN LB_Content AS other ON content.contentSectionId = other.contentSectionId
WHERE other.fullURL = '/index'
AND content.contentSlug <> 'index'
GROUP BY content.contentId
UNION
SELECT content.*, query.sectionOrder AS sortOrder
FROM LB_Content AS content, (
SELECT section.*
FROM LB_ContentSections AS section
INNER JOIN LB_Content AS other ON section.parentContentSectionId = other.contentSectionId
WHERE other.fullURL = '/index'
) AS query
WHERE content.contentSectionId = query.contentSectionId
AND content.contentSlug = 'index'
) as result,
LB_ContentTypes AS types
WHERE result.showInNavigation = 1
AND result.status = 1
AND result.published = 1
AND result.contentTypeId = types.contentTypeId
AND types.useOption = 1
GROUP BY result.contentId
ORDER BY result.sortOrder ASC
错误输出
SQLSTATE [42000]:语法错误或访问冲突:1055表达式#2 SELECT列表不在GROUP BY子句中并包含nonaggregated 专栏&#39; result.fullURL&#39;这在功能上不依赖于列 在GROUP BY子句中;这是不相容的 的sql_mode = only_full_group_by
感谢您的帮助!
答案 0 :(得分:0)
&#34;只有&#34;表示您的聚合查询必须在结果中的所有非聚合字段上进行分组。它们是否被隐藏&#34;无关紧要。在*
中,必须将这些字段分组。
此查询甚至不应该开始分组;没有使用聚合函数。如果&#34;只有&#34;不是当前的设置,这个查询将是&#34;给我一个有效的随机结果,传递where条件,为每个contentId&#34;。