当MySQLSUM()
函数获得一个没有值的列作为参数时,它将返回NULL而不是0作为输出。该列可以是任何数据类型。在此示例之后,使用名为“ social”的表仅包含一个名为“ id”的列而没有值的情况将对其进行说明。
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)