select 100*(select count(1) zs from tbname where xb='nv')/(select count(1) from tbname) col from dual;select count(1) zs from tbname where xb='nv'--查询所有MM人数 select count(1) from tbname--查询所有人数 dual--是oracle中的一个虚表,只有一行纪录。select sum(decoed(xb,'女',1,0))/count(xm) from tablename;decoed(xb,'女',1,0)--如果xb='女' 返回1 其它 返回 0应该可以看明白了吧。
先求出MM的总数(select count(1) zs from tbname where xb='nv'), 得到总人数(select count(1) from tbname) select 100*(select count(1) zs from tbname where xb='nv')/(select count(1) from tbname) col from dual;
如果使用ansi sql的话 select a.count/b.count from ( select count(*) from tbname where 性别 = '女' ) a, ( select count(*) from tbname )如果不要求ansi sql的话 select sum(decode(性别,'女',1,0)) / count(*) from tabname; or select sum(case 性别 when '女' then 1 else 0 end) /count(*) from tabname
bzszp(SongZip) 和 zhpsam109(孤寂无边) :能不能稍微注释一下
:)
select sum(decode(xb,'女',1,0))/count(xm) from tablename;
col from dual;select count(1) zs from tbname where xb='nv'--查询所有MM人数
select count(1) from tbname--查询所有人数
dual--是oracle中的一个虚表,只有一行纪录。select sum(decoed(xb,'女',1,0))/count(xm) from tablename;decoed(xb,'女',1,0)--如果xb='女' 返回1 其它 返回 0应该可以看明白了吧。
得到总人数(select count(1) from tbname)
select 100*(select count(1) zs from tbname where xb='nv')/(select count(1) from tbname)
col from dual;
select a.count/b.count
from (
select count(*) from tbname where 性别 = '女'
) a, (
select count(*) from tbname
)如果不要求ansi sql的话
select sum(decode(性别,'女',1,0)) / count(*) from tabname;
or
select sum(case 性别 when '女' then 1 else 0 end) /count(*) from tabname