当前位置:网站首页>How MySQL sums columns

How MySQL sums columns

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

mysql How to sum Columns

This article introduces “mysql How to sum Columns ” Knowledge about , During the operation of the actual case , Many people will encounter such difficulties , Next, let Xiaobian lead you to learn how to deal with these situations ! I hope you will read carefully , Be able to learn !

stay mysql in , have access to SUM() Function to sum the columns ;SUM() Is a function of summation , You can return the sum of the specified column values , grammar “SELECT SUM(DISTINCT Name ) FROM Table name ;”,“DISTINCT” Operator allows you to evaluate different values in a collection ;SUM() When the function is evaluated , Column values of NULL The line of .

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

stay mysql in , have access to SUM() Function to sum the columns .

SUM() Is a function of summation , Returns the sum of the values of the specified column . grammar :

SELECT SUM(DISTINCT  Name ) FROM  Table name ;
  • DISTINCT Operator allows you to evaluate different values in a collection

explain :

  • If no matching line is returned in the SELECT Use in statement SUM function , be SUM The function returns NULL, instead of 0.

  • SUM() When the function is evaluated , Column values of NULL The line of

mysql SUM() Column summation example

Create a student transcript tb_students_score

CREATE TABLE tb_students_score(id INT(11),student_name VARCHAR(25),student_score INT(11));

mysql How to sum Columns

After inserting data , View the data

mysql How to sum Columns

Use sum() Function in tb_students_score Calculate the total score of students' grades in the table

SELECT SUM(student_score) FROM tb_students_score;

mysql How to sum Columns

“mysql How to sum Columns ” That's all for , Thanks for reading . If you want to know more about the industry, you can pay attention to Yisu cloud website , Xiaobian will output more high-quality practical articles for you !

原网站

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