当我把ubuntu从15.10升级到16.04时,我的yii2项目中出现了这个错误

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

如何解决我的问题?

推荐答案

在select you have aggregate function named sum and set of column name中,错误告诉您尚未在group by子句中指定正确的列名列表.可能是您应该在group by中添加更多可能与profile_details, opportunity_conditions表相关的列名称

你也有,(opportunity.id),(opportunity_conditions.money), (opportunity.mantaghe), 个为什么()如果你需要总和,你必须把总和加到所有列

sum(opportunity.id), sum(opportunity_conditions.money),

sum(opportunity.mantaghe),

否则,如果这是普通列,则应使用不带()

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

基本列名上有group by(我希望)

GROUP BY`opportunity`.`id`,   `profile_details`.`user_id`,`opportunity_conditions.money`,  

Mysql相关问答推荐

MySQL INSERT INSERT ON DIPLICATE KEY UPDATE WITH COMPAY PRIMARY KEY失败

客户跨订阅的跨时间线计数

对多个数据库运行UPDATE mySQL查询

SQL MaxSum查询为列 Select 了不正确的值

在 mySQL 中计算每日数组的每周指标

如果其中一个表为空,则 mysql 中的查询会给出 0 个结果

任何值的 SQL WHERE 子句?

sequelize 中最好的更新方法是什么

使用来自另一个表 mysql 的值将新行插入到表中

MySQL 使用了错误的索引

在 Presto Athena 中将字符串转换为数组

使用 MySQL LIMIT、OFFSET 进行分页

MySQL:使用来自查询的信息创建一个新表

在 PHP 中获取 MySQL 列的总和

MYSQL:创建表中的索引关键字以及何时使用它

授予用户对 MySQL 中有限数量表的访问权限

org.hibernate.InstantiationException:没有实体的默认构造函数::principal.Cliente

如何在sequelize中定义多列的唯一索引

MySQL行格式:固定和动态之间的区别?

Hibernate 生成的 DDL 中的无效语法错误type=MyISAM