求一条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的行数
……