select count(*) form table1 where (a is null)为空 select count(*) form table1 where (a is not null)不为空
select count(*) form table1 where (a is null)为空 select count(*) form table1 where (a is not null)不为空
楼上的回答不行,我要用一条SQL语句统计,统计结果要显示在网格中
SELECT (SELECT COUNT(A) FROM table1 WHERE (A = NULL)) AS NC,(SELECT COUNT(A) FROM table1 WHERE (A <> NULL)) AS N
select count(A) from table where not (A is null)
select sum(case when 字段 is null then 1 else 0 end) as 记录为空的数量, sum(case when 字段 is not null then 1 else 0 end) as 记录不为空的数量 from table
select '记录为空的' AS 统计项, sum(case when 字段 is null then 1 else 0 end) as 数量 from table union select '记录不为空的' as 统计项, sum(case when 字段 is not null then 1 else 0 end) as 数量 from table
select '记录为空的' as 统计项, sum(case when 字段 is null then 1 else 0 end) as 数量 from table union select '记录不为空的' as 统计项, sum(case when 字段 is not null then 1 else 0 end) as 数量 from table
select * from (select sum(1) as 为空的数量 from t1 where f1 is null)a, (select sum(1) as 不为空的数量 from t1 where f1 is not null)b
create table ai (a tinyint null,aa tinyint not null) insert into ai values(1,2) insert into ai values(2,2) insert into ai values(4,4) insert into ai(aa) values(2)select * from aiselect (select count(*) from ai where a is null or aa is null) as 空行数量, (select count(*) from ai where a is not null and aa is not null) as 不空行数量
create table ai (a tinyint null,aa tinyint not null) insert into ai values(1,2) insert into ai values(2,2) insert into ai values(4,4) insert into ai(aa) values(2)select * from ai1-- select (select count(*) from ai where a is null or aa is null) as 空行数量, (select count(*) from ai where a is not null and aa is not null) as 不空行数量2--- select '记录为空的' AS 统计项, sum(case when a is null or aa is null then 1 else 0 end) as 数量 from ai union select '记录不为空' as 统计项, sum(case when a is not null and aa is not null then 1 else 0 end) as 数量 from ai
select count(*) form table1 where (a is not null)不为空
select count(*) form table1 where (a is not null)不为空
sum(case when 字段 is not null then 1 else 0 end) as 记录不为空的数量
from table
sum(case when 字段 is null then 1 else 0 end) as 数量
from table
union
select '记录不为空的' as 统计项,
sum(case when 字段 is not null then 1 else 0 end) as 数量
from table
sum(case when 字段 is null then 1 else 0 end) as 数量
from table
union
select '记录不为空的' as 统计项,
sum(case when 字段 is not null then 1 else 0 end) as 数量
from table
(select sum(1) as 为空的数量 from t1 where f1 is null)a,
(select sum(1) as 不为空的数量 from t1 where f1 is not null)b
insert into ai values(1,2)
insert into ai values(2,2)
insert into ai values(4,4)
insert into ai(aa) values(2)select * from aiselect (select count(*) from ai where a is null or aa is null) as 空行数量,
(select count(*) from ai where a is not null and aa is not null) as 不空行数量
insert into ai values(1,2)
insert into ai values(2,2)
insert into ai values(4,4)
insert into ai(aa) values(2)select * from ai1--
select (select count(*) from ai where a is null or aa is null) as 空行数量,
(select count(*) from ai where a is not null and aa is not null) as 不空行数量2---
select '记录为空的' AS 统计项,
sum(case when a is null or aa is null then 1 else 0 end) as 数量
from ai
union
select '记录不为空' as 统计项,
sum(case when a is not null and aa is not null then 1 else 0 end) as 数量
from ai