首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

数据统计有关问题,求解答,

2013-12-19 
数据统计问题,求解答,急急急!表TB有4个字段A、B、C、D,实例如下 A B C D 1 1 2 2 3 1 2 4 1 1 1 1 5 6 7 8 9

数据统计问题,求解答,急急急!
表TB有4个字段A、B、C、D,实例如下

 A B C D
 1 1 2 2
 3 1 2 4
 1 1 1 1
 5 6 7 8
 9 5 8 1
[解决办法]

select sum(case when A=1 then 1 else 0 end)+
 sum(case when B=1 then 1 else 0 end)+
 sum(case when C=1 then 1 else 0 end)+
 sum(case when D=1 then 1 else 0 end) as [1的次数]

from tb

[解决办法]
如果不懂就用这个,这个应该非常好懂

select count(*) from
(select * from TB where A=1
union all 
select * from TB where B=1
union all 
select * from TB where C=1
union all 
select * from TB where D=1
) TT 

热点排行