当 mysql sum() 函数与没有返回匹配行的 select 语句一起使用时,则没有任何内容可评估,并且它返回 null 作为输出。有时,我们认为它必须返回 0 作为输出,但 0 本身就是一个数字,对于没有匹配的行,返回 0 并不重要,因此它返回 null。要理解上述概念,请考虑一个“employee_tbl”表,该表具有以下记录 -
mysql> select * from employee_tbl;+------+------+------------+--------------------+| id | name | work_date | daily_typing_pages |+------+------+------------+--------------------+| 1 | john | 2007-01-24 | 250 || 2 | ram | 2007-05-27 | 220 || 3 | jack | 2007-05-06 | 170 || 3 | jack | 2007-04-06 | 100 || 4 | jill | 2007-04-06 | 220 || 5 | zara | 2007-06-06 | 300 || 5 | zara | 2007-02-06 | 350 |+------+------+------------+--------------------+7 rows in set (0.00 sec)
现在,当我们运行以下查询来查找“mohan”(不在“name”列中的名称)输入的总页数时,mysql sum() 函数返回 null -mysql> select sum(daily_typing_pages) from employee_tbl where name = ‘mohan’;+-------------------------+| sum(daily_typing_pages) |+-------------------------+| null |+-------------------------+1 row in set (0.00 sec)
以上就是mysql sum() 函数如何评估它是否与返回不匹配行的 select 语句一起使用?的详细内容。