sql NULL,ISNULL(),NULLIF()。sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql NULL,ISNULL(),NULLIF()。sql相关的知识,希望对你有一定的参考价值。

-- NULLs - NULL means unknown, not zero or empty. Therefore, NULL = NULL returns False (it is unknown if the first unknown NULL is equal to the second unknown NULL), NULL IS NULL returns True (is unknown null unknown? yes)

-- ISNULL(), returns a specific value if a NULL is found in any row. This is useful for things like returning a 0 where a NULL is returned. Format is ISNULL(column to select, value to return if a NULL is present). In the example below, all NULLs found in the PromoPoints column will be replaced with a 0.
SELECT ISNULL(PromoPoints, 0) FROM orders1;

-- NULL(IF), returns a NULL if a certain value is found in any row. Format is NULLIF(column to select, value when found to be switched out with a NULL). In the example below, when the value 'Red' is found in the results, it'll be returned as a NULL.
SELECT NULLIF(Colors, 'Red') FROM orders1;

以上是关于sql NULL,ISNULL(),NULLIF()。sql的主要内容,如果未能解决你的问题,请参考以下文章

mysql几个常用的判空函数:isnull, ifnull, nullif, coalesce

SQL中isnullifnull和nullif函数用法

MySQL-ISNULL()IFNULL()和NULLIF()函数

MySQLMySQL的IFNULL()ISNULL()NULLIF()函数用法说明

MySQLMySQL的IFNULL()ISNULL()NULLIF()函数用法说明

MySQL 的IFNULL()ISNULL()和NULLIF()函数