In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
The purpose of this article is to share with you the analysis of the problem that Groupby is compatible with the incorrect use of SQL statements in Mysql. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
First, create the database hncu and create the stud table.
Add data:
Create table stud (sno varchar (30) not null primary key,sname varchar (30) not null,age int,saddress varchar (30)); INSERT INTO stud VALUES ('1001mpg); INSERT INTO stud VALUES (' 1002mpg); INSERT INTO stud VALUES ('1003pr' Li Bai', 22nd 'Yiyang'); INSERT INTO stud VALUES ('1004pi' Wang Wu', 24pi 'Beijing, China') INSERT INTO stud VALUES ('1005 Zhangsan', 22 'Yiyang'); INSERT INTO stud VALUES ('1006 Zhangsi', 23 'Yiyang'); INSERT INTO stud VALUES ('1007 Zhangsi', 22 'Hunan Yiyang'); INSERT INTO stud VALUES ('1008 Li Bei, 24 Beijing')
The execution statement is as follows:
VcD4NCjxwcmUgY2xhc3M9 "brush:sql;" > SELECT * FROM stud GROUP BY saddress
The following error is displayed:
ERROR 1055 (42000): Expression # 1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hncu.stud.sno' which is not functionally dependenton columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Then execute this sentence:
Average age of SELECT saddress as FROM stud GROUP BY saddress
-No problem.
Then we use MySQL to execute the wrong code in the previous sentence:
That is:
SELECT * FROM stud GROUP BY saddress
Let's look at the results:
Passed smoothly, however, you found no, the previous smo,sname,age, these three columns of data is not correct ah, yes, MySQL forced to show the first time to find a different saddress line! In fact, this result is wrong, but MySQL should be compatible with this error!
On the other hand, DOS is strictly in accordance with the syntax of SQL.
The grop by syntax for SQL is that select selects the columns in the grouping + aggregate function from table names group by grouped columns
From the perspective of grammatical format, there is a grouping first, and then the retrieved columns are determined, and the retrieved columns can only be selected from the columns that participate in the grouping.
So in the question, the a _ group by _ b _ Q _ c is determined first. It is only after select that a _ can be changed. That is,
The following statements are correct:
Select a from table_name group by c from table_name group by a select a from table_name group by
The following statement is wrong:
Select a from table_name group by c from table_name group by a pm select a cent c from table_name group by a
And because of the power of MySQL, it is compatible with this error!
But not in DOS. So there is a situation where an error is reported under DOS and can be looked up in MySQL (in fact, the result of this search is wrong).
Thank you for reading! On the "Mysql misuse of SQL statements Groupby compatible problem analysis" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.