avg函数.
统计a列的平均值时候.忽略a值为null的记录
insert into test(a,b) values (5,1)
insert into test(a,b) values (5,null)
insert into test(a,b) values (5,0)
insert into test(a,b) values (5,3)
select avg(t.b) from test t
select avg(nvl(t.b,0)) from test t
select avg(nullif(t.b,'0')) from test t //是2
select count(t.b) from test t
not in也与null有关
oracle中:
NVL (expr1, expr2)->expr1为NULL,返回expr2;不为NULL,返回expr1。注意两者的类型要一致
NVL2 (expr1, expr2, expr3) ->expr1不为NULL,返回expr2;为NULL,返回expr3。expr2和expr3类型不同的话,expr3会转换为expr2的类型
NULLIF (expr1, expr2) ->相等返回NULL,不等返回expr1