which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod

sql语句:

SELECT a.stock_out_date,a.bill_code,b.bd_inventory_inv_pinpai,b.bd_inventory_inv_type,b.bd_inventory_inv_spec,sum(b.num) as num,null as remark,b.vbdef7,sum(b.vbdef11) as vbdef11
 FROM bm_stock_out a,bm_stock_out_child b 
WHERE a.bill_code = b.bm_father_code AND a.bill_code='CK2012210001'
 group by bd_inventory_inv_pinpai,bd_inventory_code


在mysql 5.7版本下可能会报如下错误

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

新建查询:


SELECT @@sql_mode

默认可能是以下结果:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


原因 是在5.7下mysql的model默认【ONLY_FULL_GROUP_BY】模式。


解决:

修改mysql的配置文件

在[mysqld]下增加如:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重启mysql服务器,问题解决。

qrcode