sum函数是对列的值进行统计，求和；  www.2cto.com
count函数对满足条件的列进行累计，满足条件就加一。

[sql]
select count(*) from student where sex='M'

[sql]
select sum(achv) from score where stu_name='Scott' and stu_id='120010'

[sql]
select sum(case when sex='M' then 1 else 0 end)
from student

[sql]
select 'all',count(*)
from employee
union all
select 'man',count(*)
from employee
where sex='M'
1   2
--- -----------
man          23
all          42

[sql]
select 'man',sum(case when sex='M' then 1 else 0 end)
from employee
union all
select 'all',count(*)
from employee
1   2
--- -----------
all          42
man          23

[sql]
select 'man',count(*)
from employee
where sex='M'
union all
select 'femail',count(*)
from employee
where sex ='F'
union all
select 'all',count(*)
from employee
1      2
------ -----------
man             23
femail          19
all             42

count(*)常用于统计符合条件的行数；
count(0)或者count(1)在统计符合记录的行数目，与count(*)相同作用；
count(column_name)就不一样了，它将会过滤掉column is null的值。
[sql]
select count(case when 1=0 then 1 else null end)cnt1,
count(case when 1=1 then 1 else null end) cnt2
from sysibm.sysdummy1
CNT1        CNT2
----------- -----------
0           1

[sql]
db2 => select * from test01
COL1  COL2
----- -----
A01   -
-     B01
-     -
A02   B02
A03   -

db2 => select count(*) cnt1,count(1) cnt2,count(col1) cnt3,count(col2) cnt4 from test01
CNT1        CNT2        CNT3        CNT4
----------- ----------- ----------- -----------
5           5           3           2
count是对符合条件的记录进行统计，也就是说我们读取一条记录，判断其符合条件之后，就让统计变量自增1，

[sql]
select count(*) all,
sum(case when sex='M' then 1 else 0 end) man,
sum(case when sex='F' then 1 else 0 end) femail
from employee
ALL         MAN         FEMAIL
----------- ----------- -----------
42          23          19

--the end--