group by 语句报错 this is incompatible with sql_mode=only_full_group_by

### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘zbc_jssltj8.zbf.wrfxqfxjcsm‘ which is not functionally dependent on columns in GROUP BY clause; 
### The error may exist in file [D:\706\code\jssltj2\jssltj\casic-zbc\target\classes\mapper\zbc\ZbDataStatisticsAndAuditMapper.xml]

 

解决方法:

SELECT zbf.zb_code AS zbCode,
zbf.zb_name AS zbName,
CAST( sum( IFNULL( zbf.nowEquipmentCount, 0 ) ) AS DECIMAL ( 15,0 ) ) AS nowEquipmentCount,
CAST( sum( IFNULL( zbf.wrfxqljfxjc ,0 ) ) AS DECIMAL ( 15,0 ) ) as wrfxqljfxjc,
CAST( sum( IFNULL( zbf.bjwrfxqfxjc, 0 ) ) AS DECIMAL ( 15,0 ) ) as bjwrfxqfxjc,
CAST( zbf.wrfxqfxjcsm AS DECIMAL ( 15,0 ) ) as wrfxqfxjcsm,
CAST( sum( zbf.wrfxqfxjccbs ) AS DECIMAL ( 15,0 ) ) as wrfxqfxjccbs,
CAST( (sum(IFNULL(wrfxqfxjccbs, 0 )))*100/(sum(IFNULL(wrfxqfxjcsm*nowEquipmentCount,0))) AS DECIMAL ( 15, 2 ) ) AS wrfxqfxjccbRate,
zbf.szjd
FROM zb_fxqfxsj zbf
LEFT JOIN zb_equipment ze ON zbf.zb_code = ze.zbdm
group by zb_code,zb_name

改为

SELECT zbf.zb_code AS zbCode,
zbf.zb_name AS zbName,
CAST( sum( IFNULL( zbf.nowEquipmentCount, 0 ) ) AS DECIMAL ( 15,0 ) ) AS nowEquipmentCount,
CAST( sum( IFNULL( zbf.wrfxqljfxjc ,0 ) ) AS DECIMAL ( 15,0 ) ) as wrfxqljfxjc,
CAST( sum( IFNULL( zbf.bjwrfxqfxjc, 0 ) ) AS DECIMAL ( 15,0 ) ) as bjwrfxqfxjc,
CAST( max(zbf.wrfxqfxjcsm) AS DECIMAL ( 15,0 ) ) as wrfxqfxjcsm,
CAST( sum( zbf.wrfxqfxjccbs ) AS DECIMAL ( 15,0 ) ) as wrfxqfxjccbs,
CAST( (sum(IFNULL(wrfxqfxjccbs, 0 )))*100/(sum(IFNULL(wrfxqfxjcsm*nowEquipmentCount,0))) AS DECIMAL ( 15, 2 ) ) AS wrfxqfxjccbRate,
zbf.szjd
FROM zb_fxqfxsj zbf
LEFT JOIN zb_equipment ze ON zbf.zb_code = ze.zbdm
group by zb_code,zb_name

group by 语句报错 this is incompatible with sql_mode=only_full_group_by

上一篇:LeetCode——剑指 Offer 22. 链表中倒数第k个节点(Java)


下一篇:MySQL5.7.30详细安装教程