mysql 報錯 incompatible with sql_mode=only_full_group_by解決
使用peewee這個ORM翻譯sql并查詢數(shù)據(jù)
翻譯出來的 sql 如下,可以看到其實比較不規(guī)范,group by 里面只有 track_source_id,但是 select 里面卻有
parser_name、error_class_name、track_source_id
select
`t1`.`parser_name`,
`t1`.`error_class_name`,
`t1`.`track_source_id`,
COUNT('*') as `task_count`
from
`parse_monitoring_detail` as `t1`
where
(`t1`.`success` = 0)
group by
`t1`.`track_source_id`
order by
`task_count` desc正常情況下,執(zhí)行上面的 sql 應該報錯
SQL 錯誤 [1055] [42000]: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'crawler2.t1.parser_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
但是實際上卻沒有,為什么?
因為 peewee 創(chuàng)建連接之后,會先執(zhí)行 SET sql_mode='PIPES_AS_CONCAT'
具體可看: peewee 創(chuàng)建連接前的前置操作,wireshark 抓包
以上就是mysql 報錯 incompatible with sql_mode=only_full_group_by解決的詳細內(nèi)容,更多關于mysql incompatible報錯的資料請關注腳本之家其它相關文章!
相關文章
mysql一條sql查出多個條件不同的sum或count問題
這篇文章主要介紹了mysql一條sql查出多個條件不同的sum或count問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05

