SQLSTATE [42000]:语法错误或访问冲突:1055 SELECT列表的表达式#3不在GROUP BY子句中,并且包含未聚合的 [英] SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated
问题描述
当我将ubuntu从15.10升级到16.04时,我的yii2项目中出现了这个错误
when i got upgraded my ubuntu from 15.10 to 16.04 i have this erro in my yii2 project
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3
of SELECT list is not in GROUP BY clause and contains nonaggregated column
'iicityYii.opportunity_conditions.money' which is not functionally dependent
on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
正在执行的SQL是:
SELECT SUM(oc.money),op.id,oc.money,
op.mantaghe,
op.`time`, op.`id`, `op`.`logo`,
`pd`.`user_id`, `op`.`name`,
`pd`.`co_name`, `op`.`address`,
`op`.`project_type_id`, `op`.`state_id`
FROM `opportunity` op
INNER JOIN `profile_details` pd ON op.user_id=pd.user_id
INNER JOIN `opportunity_conditions` oc ON op.id=oc.opportunity_id
GROUP BY `op`.`id`
ORDER BY `op`.`id` DESC
如何解决我的问题?
推荐答案
在您的选择中,您具有聚合函数总和和一组列名,该错误告诉您您未在组中指定正确的列名列表按条款.可能是您应该根据可能与profile_details, opportunity_conditions
表
In your select you have an aggregate function sum and a set of column name, the error tell you that you have not specified the correct list of column name in group by clause . could be you should add more columns name in group by probably related to the profile_details, opportunity_conditions
table
您还,(opportunity.id),(opportunity_conditions.money),
(opportunity.mantaghe),
为什么()
如果需要加和,您必须将加和到所有列
You have also ,(opportunity.id),(opportunity_conditions.money),
(opportunity.mantaghe),
why the ()
if you need sum you must add sum to all column
sum(opportunity.id), sum(opportunity_conditions.money),
sum(opportunity.mantaghe)
sum(opportunity.mantaghe),
否则,如果这些是普通列,则应使用不带()的普通sintax
otherwise if thes are normal columns you should use the normal sintax without ()
opportunity.id, opportunity_conditions.money,opportunity.mantaghe,
我试图重写可能的查询
SELECT SUM(opportunity_conditions.money),
`opportunity`.`id`,
`opportunity_conditions.money`,
`opportunity.mantaghe`,
`opportunity`.`time`,
`opportunity`.`logo`,
`profile_details`.`user_id`,
`opportunity`.`name`,
`profile_details`.`co_name`,
`opportunity`.`address`,
`opportunity`.`project_type_id`,
`opportunity`.`state_id`
FROM `opportunity`
INNER JOIN `profile_details` ON `opportunity`.`user_id`= `profile_details`.`user_id` 7
INNER JOIN `opportunity_conditions` ON `opportunity`.`id`=`opportunity_conditions`.`opportunity_id`
GROUP BY`opportunity`.`id`, `profile_details`.`user_id`,`opportunity_conditions.money`,
ORDER BY `opportunity`.`id` DESC
在必填列名称上使用分组依据(希望如此)
with group by on the essential column name (i hope)
GROUP BY`opportunity`.`id`, `profile_details`.`user_id`,`opportunity_conditions.money`,
这篇关于SQLSTATE [42000]:语法错误或访问冲突:1055 SELECT列表的表达式#3不在GROUP BY子句中,并且包含未聚合的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!