请教一个统计问题
ADOQuery.SQL.Add('select count(ID) as C1,'+
'(select count(DQZK) from [TB1] where DQZK is not null) as C2,'+
'(select count(DQZK) from [TB1] where DQZK is null) as C3'+
'from [TB1] ');
ADOQuery.Open;
DQZK字段里,有些是空白没有内容的。
希望查询能分别得到
总数量、DQZK空白的数量、DQZK不是空白的数量
[解决办法]
--测试数据 mssql2000
create table TB1(id int, DQZK varchar(10));
go
insert into TB1 select 1, null;
insert into TB1 select 2, 'abc';
insert into TB1 select 3, null;
insert into TB1 select 4, 'dd';
insert into TB1 select 5, 'dv';
go
--测试代码
select C1 = sum(a) + sum(b), C2 = sum(a), C3 = sum(b)
from(
select a = case when dqzk is null then sum(1)end,
b = case when dqzk is not null then sum(1) end
from tb1 group by dqzk) a