What is the meaning in mysql?

What does group by mean in mysql syntax? After searching for a long time in Baidu, I finally found an article with a better explanation (not a blog post, but Baidu knows it, so depressed, so many netizens did not explain clearly), the link is as follows: http://zhidao.baidu.com/question /495569434771073124.htmlAccording to the database mentioned above, I built a stu myself. The operation is as follows: 1.mysql> select * from stu;+------+--------+--- ----+| name | course | score |+------+--------+-------+| Zhang San| java | 90 || Zhang San| c# | 98 || Li Si| java | 89 || Li Si| c# | 62 || Li Si| c++ | 80 |+------+--------+------ -+According to the netizens said as follows, but add an extra column of course in the select query statement, because the group is grouped by course, the effect of this display will be very obvious. 2.mysql> select course,sum(score) from stu group by course;+--------+------------+| course | sum(score) |+- -------+------------+| c# | 160 || c++ | 80 || java | 179 |+--------+---- --------+One more example: 3.mysql> select name,sum(score) from stu group by name;+------+---------- --+| name | sum(score) |+------+------------+| Zhang San| 188 || Li Si| 231 |+----- -+------------+Is it optimistic? My understanding is as follows: group by is indeed a grouping, which is to group the column element names after group by with equal content (this is Core), and then the previous function operation is to operate on these groups. For example, according to the example in step 2, the original 5 records are now grouped by course, and now they are 3 groups, and the sum operation is for each A group is summed, and the result displayed in this way is the result of the second step, the same as the third step. 

Leave a Comment

Your email address will not be published.