Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to Sum multiple columns in mysql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

The main content of this article is to explain "how to ask for sums in mysql". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "mysql how to make more summations".

In mysql, you can use the sum () function for multi-column summation, which returns the total number of numeric columns with the syntax "SELECT SUM (column 1 + column 2 + column 3.) FROM table_name;".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to Sum multiple columns in mysql

The SUM () function returns the total number of numeric columns.

SQL SUM () syntax

SELECT SUM (column_name) FROM table_name

Demo database

In this tutorial, we will use the RUNOOB sample database.

Here is the data selected from the "access_log" table:

Mysql > SELECT * FROM access_log +-+ | aid | site_id | count | date | +-+ | 1 | 1 | 45 | 2016-05-10 | 2 | 3 | 100 | 2016-05- | 13 | 3 | 1 | 2016 | 2016-05-14 | 4 | 2 | 10 | 2016-05-14 | 5 | 5 | 20 | 2016-05-14 | 6 | 4 | 13 | 2016-05-15 | 7 | 3 | 2016-05-15 | 8 | 5 | 545 | 2016-05-16 | 9 | 3 | 2016-05-17 | | | +-+ 9 rows in set (0.00 sec) |

SQL SUM () instance

The following SQL statement finds the total number of "count" fields in the "access_log" table:

Example

SELECT SUM (count) AS nums FROM access_log

2. Count the total score of all lecturers

The example syntax is as follows:

At this point, I believe you have a deeper understanding of "how to ask for sums in mysql". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report