当前位置: 代码迷 >> Sql Server >> 占表总行数的百分率解决思路
  详细解决方案

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

热度:94   发布时间:2016-04-27 17:43:49.0
占表总行数的百分率
表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
  相关解决方案