--這兩個是不同的概念....如果存在null值,結果也會不一樣.
create table t(c1 int,c2 int)
insert into t select 1,2
insert into t select 1,2
insert into t select 1,2
insert into t select null,2
insert into t select null,2
insert into t select 1,2
insert into t select 1,2select sum(c1)+sum(c2),sum(c1+c2) from tdrop table t
----------- -----------
19 15Warning: Null value is eliminated by an aggregate or other SET operation.
create table t(c1 int,c2 int)
insert into t select 1,2
insert into t select 1,2
insert into t select 1,2
insert into t select null,2
insert into t select null,2
insert into t select 1,2
insert into t select 1,2select sum(c1)+sum(c2),sum(c1+c2) from tdrop table t
----------- -----------
19 15Warning: Null value is eliminated by an aggregate or other SET operation.
這個高
當然是應該這樣寫Sum(isnull(a,0)+isnull(b,0)+isnull(c,0)...n)
insert into t select 1,2
insert into t select 1,2
insert into t select 1,2
insert into t select null,2
insert into t select null,2
insert into t select 1,2
insert into t select 1,2select sum(isnull(c1,0)+isnull(c2,0)) as a,
sum(isnull(c1,0))+sum(isnull(c2,0)) as b
from tdrop table t测试结果:
sum(isnull(c1,0)+isnull(c2,0))
效率高!
from table;
from table
譬如 if null = 1
这种比较既不会得到false也不会得到true值。