tags: mysql
Table used herein:
Table SC
+------+-------+
| sid | score |
+------+-------+
| 01 | 80.0 |
| 01 | 90.0 |
| 01 | 99.0 |
| 02 | 70.0 |
| 02 | 60.0 |
| 02 | 80.0 |
| 03 | 80.0 |
| 03 | 80.0 |
| 03 | 80.0 |
+------+-------+
SQL often appears below
ERROR 1140 (42000): In aggregated query without GROUP BY
First explain
AggRegate is a kind of function in SQL, which is calledPolymerization function, The following is a polymeric function
So this error is that you wrote a query statement containing the aggregate function but does not use the group BY group.
So why didn't you use the group by grouping?
Take the SUM function in the polymerization function as an example. SUM (score) calculates the sum column, if SID and SUM (SCORE) are selected at the same time in the SQL query statement
select sid,sum(score) from sc;
Imagine what results will be returned on the above statement? Is there a strong relationship between two columns in the result of the return?
Obviously such query statements are unknown, so there is a reasonable table that cannot be returned.
In order to make the return result reasonable, the meaning of the query statement will be further clarified.
So you need to use Group By to modify the above query statement.
The literal meaning of Group By is "packet", transfer the door in SQL to modify the aggregate function
select sid,sum(score) from sc
group by sid;
The above SQL statement means that SID is based on the basis for packets, and SCORE is subjected to summing. The SUM that has been obtained is correct with the SID. In this case, the meaning is the total division of each SID.
When the SQL query statement has selected multiple fields in addition to the aggregate function, add the relationship between group by, the truth is simple, if one of the various fields is the basis for the group, then the remaining fields It is not possible to make a clear and reasonable association with the polymerization function.
At lastBy modifying the SQL_MODE variable, it can make the polymer function to force the binding group by Return the result, the modification is as follows.
set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
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...
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 ...
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...
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...
Record an error in a mysql combination query plus grouping: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'tsbio.sl.id'; this is incompatible with sq...
wrong reason This is caused by the version features above MySQL5.7. solution Execute the following code Run and then you can, finish....
Article Directory Problem description Problem traceability Solution 1 Solution 2 appendix: Problem description Here is a screenshot of the error: Translated: In an aggregation query without group BY, ...
sql statement error contents: Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP BY, expression #1 of SELECT list contains non...
MySQL8 solves In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated... 1. Reason for error 2. Solution 2.1 Temporarily 2.2 Long-term 1. Reason for error MySQL8 is o...
The reason for this is that the mysql database version is higher than the jar package version you imported. After MySQL 5.7.5, ONLY_FULL_GROUP_BY is turned on by default, so some of the previous SQL c...