MySQL query appears in aggregated query with group by

tags: MySQL  

1. Question:

Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
In aggregated query without GROUP BY,expression #2 of SELECT list contains nonaggregated column 'pay.t.type'; this is incompatible with sql_mode=only_full_group_by

2. Reasons:
After mysql5.7.5, the only_full_group_by was opened by default, so some of the previous SQLs could not be executed normally. In fact, it was caused by our SQL irregularity. Because some of the data returned after Group By were uncertain, so it was only then possible. This error appears.

3. Solution, two types:
Option 1: Modify SQL, because this problem occurs, it is basically caused by this problem.

ANY_VALUE(column_name)
Example:
SELECT id,name,ANY_VALUE(age) FROM table1 GROUP BY name;

Option 2: Turn off only_full_group_by, mine is the Linux environment, I will talk about Linux's solution step:
① Log in to mysql, linux login: MySQL -u Username -P, and then enter the password, enter SQL: show variables like ‘%sql_mode’;
②, edit my.cnf file, the file address is generally: /etc/my.cnf ,/etc/mysql/my.cnf, find the position of the sql-mode, remove the only_full_group_by, and then restart mysql; some my.cnf does not have no in my.cnf. SQL-MODE needs to be added, pay attention to adding to [MySQLD].

[mysqld]
sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

I just joined elsewhere, and I did not take effect after restarting. The specific figure below is as follows:

③ After the modification is successful, restart the MySQL service, Service MySQL RESTART, restart it, and then log in to MySQL, enter SQL: Show Variables like ‘%SQL_Mode’; if you do n’t have_full_group_by, it means that it has been successful.

Original address

Intelligent Recommendation

MySql grouping query non-aggregated field to join

The key is that group_concat connects non-aggregated fields, the splitter is used -, distinct is used for deduplication, and concat_ws can further connect multiple fields...

MySql error: In aggregated query without GROUP BY, expression #1 of SELECT list contains....

When running the above SQL query, the error message is displayed: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'school.student.s_id'; this is incomp...

Use mysql DISTINCT function, given ERROR 1140 (42000): In aggregated query without GROUP BY .....

phenomenon: Performing sql SELECT COUNT (DISTINCT (colum1)), colum2, colum3 FROM table; error ERROR 1140 (42000): In aggregated query without GROUP BY ..... the reason: sql_mode default mysql opens up...

mysql error 1140 In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregate

In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column'szmz_zhbz_gov.b.cremation_time'; this is incompatible with sql_mode=only_full_group_by After reviewing ...

MySQL prompt: In aggregated query without GROUP BY, expression #1 of SELECT list contains ......

Preface Operating todaymysqlWhen querying data in the database, a prompt is encountered, the query fails, and the prompt message is as follows: When running this SQL statement, there is no problem: Bu...

More Recommendation

Mysql error 1140 - in aggregated query without group by, express number # 1 of success list contains nonaGgreg

Execute SQL query statement: Wrong [Err] 1140 - In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'cust_cx.c.card_type_name'; this is incompatible with s...

MySQL error: in aggregated query without group by, expression # 2 of success list contacts nona Select List Contains non

reason: 1. The official explanation of this mode: Only_Full_Group_by is a SQL_Mode provided by the MySQL database, guaranteed by this SQL_Mode, SQL statement "the highest value" legality che...

MySQL || Removement: in aggregated query without group by, expression # 1 of success list contains nonaGregate

Shatter Brother Meng, I Hu Han San is coming back again (.. ∀ ·) ノ゙ ノ゙¯ ▽ ¯ *) § First, the problem description Today, I do SQL in the cow passenger net: the course of the...

[MySQL Query] condition of sorting aggregated packet paging query

Sort query Syntax: order by clause order by sort field 1 Sort 1, Sort field 2 Sort 2 ... Sort by: ASC: Ascending order, default. DESC: In descending order. note: If there are a plurality of sorting cr...

Mysql group query (group by)

Group query 1 grammar 2 Features 1, the field that is queried with the grouping function must be the field that appears after group by 2, screening is divided into two categories: pre-group screening ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top