占表总行数的百分率解决思路

占表总行数的百分率表A结构字段IDintidentity(1,1)statusintnotnulldefault0status默认为0,值为1或0求STAT

占表总行数的百分率
表A结构
字段       ID       int   identity(1,1)
              status   int   not   null   default   0      
        status   默认为0   ,值为1或0
求STATUS字段为1时
  占表总行数的百分率     可以用ID来统计表的总行数
谢谢


[解决办法]
select sum(status)*1.0/count(*) as 比率
from a

[解决办法]
or(好像通用点)

select sum(case status when 1 then 1 else 0 end)*1.0/count(*) as 比率
from a

[解决办法]
select rtrim(sum(status)*100.0/count(*))+ '% ' from a