错误代码:
ERROR 1055 (42000) at line 4: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
解决方法1:
将未进行分组统计的其他列全部加入到group by后面
select
Company.company_code,
Company.founder,
count(distinct Lead_Manager.lead_manager_code),
count(distinct Senior_Manager.senior_manager_code),
count(distinct Manager.manager_code),
count(distinct Employee.employee_code)
from Company
left join Lead_Manager on Company.company_code = Lead_Manager.company_code
left join Senior_Manager on Lead_Manager.lead_manager_code = Senior_Manager.lead_manager_code
left join Manager on Senior_Manager.senior_manager_code = Manager.senior_manager_code
left join Employee on Manager.manager_code = Employee.manager_code
group by Company.company_code,Company.founder
order by Company.company_code;
上面sql的问题链接: New Companies | HackerRank
解决方法2:
MySQL问题:ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY_微步_ym的博客-优快云博客
当遇到MySQL错误1055时,这通常是因为查询中包含了非聚合列且未在GROUP BY子句中指定。解决方法包括将所有未聚合的列添加到GROUP BY中,或者调整SQL模式。例如,一个左连接查询可能需要对所有公司和创始人进行分组,并计算各个级别的管理者数量。同时,可以参考相关博客文章获取更详细的解决方案。
1万+

被折叠的 条评论
为什么被折叠?



