当前位置:网站首页>How MySQL implements grouping sum

How MySQL implements grouping sum

2022-06-21 20:07:00 Yisu cloud

mysql How to achieve grouping sum

This article mainly introduces “mysql How to achieve grouping sum ”, In daily operation , I believe a lot of people are mysql There are doubts about how to achieve grouping sum , Xiao Bian consulted all kinds of materials , Sort out simple and easy-to-use operation methods , I hope to answer ”mysql How to achieve grouping sum ” Your doubts help ! Next , Please follow Xiaobian to learn !

stay mysql in , You can use “GROUP BY” Key words and SUM() Function to implement grouping summation , The grammar is “SELECT SUM( Field name to sum ) FROM Table name GROUP BY Field names to be grouped ;”.“GROUP BY” Keywords can group query results according to one or more fields , and SUM() The function returns the sum of the specified fields in different groups according to the grouping situation .

The operating environment of this tutorial :windows7 System 、mysql8 edition 、Dell G3 The computer .

stay mysql in , You can use “GROUP BY” Key words and SUM() Function to implement grouping summation .

  • “GROUP BY” Keywords can group query results according to one or more fields

  • SUM() The function returns the sum of the specified fields in different groups according to the grouping situation

SELECT SUM( Field name to sum ) FROM  Table name  GROUP BY  Field names to be grouped ;

Example : For the data table mip_demo Of sex Field for grouping query , Then find out by grouping score The sum of the scores of boys and girls in the field .

Let's take a look first mip_demo The data table :

SELECT * FROM mip_demo;

mysql How to achieve grouping sum

Divide into groups to find the sum of boys' and girls' scores .

SELECT sex,SUM(score) FROM mip_demo GROUP BY sex;

mysql How to achieve grouping sum

Here we are , About “mysql How to achieve grouping sum ” That's the end of my study , I hope we can solve your doubts . The combination of theory and practice can better help you learn , Let's try ! If you want to continue to learn more related knowledge , Please continue to pay attention to Yisu cloud website , Xiaobian will continue to strive to bring you more practical articles !

原网站

版权声明
本文为[Yisu cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211827198414.html