this is incompatible with sql_mode=only_full_group_by 报错解决办法

在mysql5.5升级到5.7 或8.0 ,数据库默认sqlMode 是默认only_full_group_by,导致聚合SQL报错

SQL: select a.deptname,ROUND(sum(a.outdata)*0.0001,2) outPolicy,ROUND(sum(a.innerdata)*0.0001,2) innerPolicy from( ( SELECT (case sd.pid when ‘1067246875800000066’ then sd.id else sd.pid end ) deptid, (case sd.pid when ‘1067246875800000066’ then sd.name else

(select name from sys_dept sd1 where sd1.id=sd.pid )end ) deptname, ‘0’ as innerdata, tio.insured_premium outdata FROM tb_insured_out_policy tiop LEFT JOIN tb_insured_out tio ON tiop.id = tio.policy_id LEFT JOIN sys_user su on tio.creator=su.id LEFT JOIN sys_dept sd on sd.id=su.dept_id WHERE tiop.state = ‘1’ AND tiop.create_date > YEAR (NOW()) and tio.insured_premium is not null AND
(SELECT count(0) FROM act_hi_taskinst WHERE PROC_INST_ID_ = tiop.instance_id AND TASK_DEF_KEY_ = ‘review_check’) > 0 ) UNION ( select (case sd.pid when ‘1067246875800000066’ then sd.id else sd.pid end ) deptid, (case sd.pid when ‘1067246875800000066’ then sd.name else (select name from sys_dept sd1 where sd1.id=sd.pid )end ) deptname, sum(tpi.premium) innerdata,‘0’ as outdata from tb_policy_info tpi
LEFT JOIN tb_policy_needs tpn on tpn.id=tpi.needs_id LEFT JOIN sys_user su on tpn.creator=su.id LEFT JOIN sys_dept sd on sd.id=su.dept_id
WHERE tpn.create_date >YEAR (NOW()) and tpi.is_effect=‘2’ GROUP BY tpn.creator ) ) a GROUP BY a.deptid

Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘a.deptname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘a.deptname’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

解决办法
修改配置文件my.cnf

找到my.cnf,添加一下配置:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重启mysql即可。
service mysqld restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值