mysql ERROR 1140 (42000): In aggregated query without GROUP BY

mysql和oracle不一样mysql可以通过设置sql_mode可以支持下边写法

mysql> SET sql_mode = ''; Query OK, 0 rows affected (0.00 sec)
mysql> SELECT owner, COUNT(*) FROM pet; +--------+----------+ | owner | COUNT(*) | +--------+----------+ | Harold | 8 | +--------+----------+ 1 row in set (0.00 sec)

如果sql_mode设置这种就报错了

mysql> SET sql_mode = 'ONLY_FULL_GROUP_BY';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT owner, COUNT(*) FROM pet;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression
#1 of SELECT list contains nonaggregated column 'menagerie.pet.owner';
this is incompatible with sql_mode=only_full_group_by

 

posted @ 2023-03-14 22:16  蚌壳里夜有多长  阅读(603)  评论(0)    收藏  举报