Mysql执行分组查询语句报错[Err] 1055 - 'bs4Order.tb_buyer_ticket_price.id' isn't in GROUP BY

1.执行sql 

SELECT
    `id`,
     count(passenger_type) AS passenger_count
FROM
    tb_buyer_ticket_price
WHERE
    1 = 1
AND ticket_order_no = ''
GROUP BY
    passenger_type;

错误信息

  [Err] 1055 - 'bs4Order.tb_buyer_ticket_price.id' isn't in GROUP BY

2.先执行sql 查看当前设置

SELECT @@GLOBAL.SQL_mode;

"ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

将ONLY_FULL_GROUP_BY值去掉即可

3.执行sql修改sql_mode 值

SET @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

4.重新打开一个新的窗口执行sql

结果正确

 

PS

这种方式仅是通过sql修改,要永久的修改的 

https://blog.csdn.net/weixin_42373127/article/details/88866710

 

你可能感兴趣的:(数据库,数据库)