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
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!