组函数不计算null值
?
SELECT SUM(a) FROM ( SELECT 1 a FROM dual UNION SELECT 2 a FROM dual UNION SELECT 3 a FROM dual );
?结果是6
?
?
?
?
SELECT SUM(a) FROM ( SELECT 1 a FROM dual UNION SELECT 2 a FROM dual UNION SELECT 3 a FROM dual UNION SELECT NULL a FROM dual );
??结果还是6
?
?
?
例如:http://blog.itpub.net/23650854/viewspace-684335
select rownum,a from t_null;
??? ROWNUM????????? A
---------- ----------
???????? 1
???????? 2
???????? 3
z@test10gr2> select sum(a) from t_null;
??? SUM(A)
----------
? ? NULL
?
select rownum,a from t_null;
ROWNUM A
---------- ----------
1
2
3
4 77
select sum(a) from t_null;
SUM(A)
----------
77
?
?
?
?
?
?