日期:2014-05-16  浏览次数:22334 次

求一条SQL语句
有以下一个表table1
id name value
1 a 0
2 b 1
3 c 10
4 d 2
5 e 0

我是想要一条SQL语句算出value大于0的比例,例如这里就是60%

------解决方案--------------------
SQL code
select count(case when value=0 then 1 end)/count(case when value>0 then 1 end) 
from tb

------解决方案--------------------
select sum(if(value>0,1,0))/count(*) 
from tt

------解决方案--------------------
select (select count(*) from table1 where value>0)/(select count(*) from table1);
------解决方案--------------------
探讨

引用:

引用:

select (select count(*) from table1 where value>0)/(select count(*) from table1);


假如,我要求:
value的和(sum)、value大于0的和(sum)、value的行数、value大于0的行数
……