mysql - SELECT 列表不在 GROUP BY 子句中并且包含非聚合列 .... 与 sql_mode=only_full_group_by 不兼容

标签 mysql group-by mysql-error-1055

AM 在我的带有 WAMP 服务器的 Windows PC 上使用 MySQL 5.7.13

我的问题是在执行这个查询时

SELECT *
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND
      `status` = 'Active'
GROUP BY `proof_type`

总是出现这样的错误

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'returntr_prod.tbl_customer_pod_uploads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

你能告诉我最好的解决方案吗...

我需要类似的结果

+----+---------+---------+---------+----------+-----------+------------+---------------+--------------+------------+--------+---------------------+---------------------+
| id | user_id | load_id | bill_id | latitude | langitude | proof_type | document_type | file_name    | is_private | status | createdon           | updatedon           |
+----+---------+---------+---------+----------+-----------+------------+---------------+--------------+------------+--------+---------------------+---------------------+
|  1 |       1 | 78      | 1       | 21.1212  | 21.5454   |          1 |             1 | id_Card.docx |          0 | Active | 2017-01-27 11:30:11 | 2017-01-27 11:30:14 |
+----+---------+---------+---------+----------+-----------+------------+---------------+--------------+------------+--------+---------------------+---------------------+

最佳答案

这个

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'returntr_prod.tbl_customer_pod_uploads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

通过这个命令改变MySQL中的sql模式就可以解决了,

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

这对我也有用.. 我用了这个,因为在我的项目中有很多这样的查询所以我只是将这个sql模式改为only_full_group_by

或者简单地包括 SELECT 语句指定的 GROUP BY 子句中的所有列。 sql_mode 可以保持启用状态。

谢谢... :-)

关于mysql - SELECT 列表不在 GROUP BY 子句中并且包含非聚合列 .... 与 sql_mode=only_full_group_by 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41887460/

相关文章:

javascript - 使用带有 Node.js 的 REST api 服务器连接到我的 sql 数据库时出现问题

java - Session.get 在 hibernate 中工作,同时逐步调试,但在 eclipse 中运行时不工作

MySQL 如何在使用 Group By 时为不匹配的列分配空值

mysql - SQL如何计算至少有1,5,10,20等交易的信用卡数量

MySQL : isn't in GROUP BY

php - 两两遍历结果数组

mysql - 如何在包含表示日期的文本的列上使用 ORDER BY?

mysql - 关于连接表的 SQL

每次查询时出现 MySQL 错误 1055 information_schema.PROFILING.SEQ

php - only_full_group_by : "ORDER BY clause is not in GROUP BY clause"