Select
(Select IsNull(Count(*),0) from INFO Where A=1) As N'A等于1的个数',
(Select IsNull(Count(*),0) from INFO Where B=0) As N'B等于0的个数'
(Select IsNull(Count(*),0) from INFO Where A=1) As N'A等于1的个数',
(Select IsNull(Count(*),0) from INFO Where B=0) As N'B等于0的个数'
sum(case where a=1 then 1 else 0 end) as A為1的個數﹐
sum(case where b=0then 1 else 0 end) as B為0的個數
from info
Create table INFO
(A Int,
B Int)
GO
--插入数据
Insert INFO Values(1,2)
Insert INFO Values(2,0)
Insert INFO Values(3,1)
Insert INFO Values(1,0)
Insert INFO Values(2,0)
GO
--测试
Select
(Select IsNull(Count(*),0) from INFO Where A=1) As N'A等于1的个数',
(Select IsNull(Count(*),0) from INFO Where B=0) As N'B等于0的个数'
GO
--删除测试环境
Drop table INFO
--结果
/*
A等于1的个数 B等于0的个数
2 3
*/
我的意思是“select
sum(case where a=1 then 1 else 0 end) as A為1的個數﹐
sum(case where b=0then 1 else 0 end) as B為0的個數
from info
”
这个好像会出错!不是你写的那个