Oracle ——count(*) 与count(列名)的区别

来源:互联网 发布:直播视频录制软件 编辑:程序博客网 时间:2024/06/06 09:33

以学生成绩为例,一共七名学生,有两名学生没有参加考试,成绩为空,如图

select count(*) as 行的总数 from result; --返回表格中行的总数 包括null行 结果为7

select count(studentresult) as 行的总数 from result;--返回表格中不为null的行的总数结果为5

 

select count(*) as null的个数 from result where studentresult is null;  结果为2

select count(*) as 不为空的个数 from result where studentresult is not null;结果为5

 
select count(studentresult ) as 空的个数 from result where studentresult is null;结果为0

对于这个结果小伙伴们可以体会一下,把这个句子分开来理解,因为select count(studentresult) as 行的总数 from result结果为5 ,里面已经没有空值,其后面再附加条件where studentresult is null,结果为0

select count(studentresult ) as 不为空的个数 from result where studentresult is not null;结果为5

 

 

QQ:771450648

 

0 0