DescribeSocial;+-------+--- ----------+------+-----+---------+-------+|Field|Type |Null|Key |Def"/> DescribeSocial;+-------+--- ----------+------+-----+---------+-------+|Field|Type |Null|Key |Def">

Home  >  Article  >  Database  >  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
WBOYforward
2023-09-06 19:49:021144browse

如果将没有值的列作为参数传递,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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete