-- null 默认的表的列可以存放null值
--- 1. is null
select * from base_student where stuname is null;
--- 2. is not null
select * from base_student where stuname is not null;
--- 3. 假如我们希望null值是 0 (如果某个列是null,将不利于计算。把值是null就返回1就好了)
---- NVL(), IFNULL() 和 COALESCE() 函数也可以达到这种结果。
----- <1> oracle中可以使用 NVL() 函数达到这种结果
select productname,unitPrice* ( unitsStock + NVL(unitsonorder,0) ) from products;
----- <2> sql server 中使用 ISNULL()
select productname,unitPrice* ( unitsStock + ISNULL(unitsonorder,0) ) from products;
---- <3> my sql 中 使用 IFNULL() 或者 COALESCE()
---- MySQL 也拥有类似 ISNULL() 的函数。不过它的工作方式与微软的 ISNULL() 函数有点不同。
select productname,unitPrice* ( unitsStock + IFNULL(unitsonorder,0) ) from products;
select productname,unitPrice* ( unitsStock + COALESCE(unitsonorder,0) ) from products;