Home > Database > Mysql Tutorial > What is the output of the MySQL SUM() function if a column with no value is passed as a parameter?

What is the output of the MySQL SUM() function if a column with no value is passed as a parameter?

WBOY
Release: 2023-09-06 19:49:02
forward
1201 people have browsed it

如果将没有值的列作为参数传递,MySQL SUM() 函数的输出是什么?

When the MySQL SUM() function takes a column with no value as a parameter, it returns NULL instead of 0 as output. The column can be of any data type. As per the following example, using a table named "social" which has only one column named "id" with no value, it will be explained

Example

mysql> Describe Social;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Id    | int(11)     | YES  |     |   NULL  |       |
| Name  | varchar(20) | YES  |     |    NULL |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> Select * from Social;
Empty set (0.00 sec)

mysql> Select SUM(id) from Social;
+---------+
| SUM(id) |
+---------+
| NULL    |
+---------+
1 row in set (0.00 sec)

mysql> Select SUM(Name) from Social;
+-----------+
| SUM(Name) |
+-----------+
| NULL      |
+-----------+
1 row in set (0.00 sec)
Copy after login

The above is the detailed content of What is the output of the MySQL SUM() function if a column with no value is passed as a parameter?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template