select 100*(select count(1) zs from tbname where xb='nv')/(select count(1) from tbname)
col from dual;

解决方案 »

  1.   

    select sum(decoed(xb,'女',1,0))/count(xm) from tablename;
      

  2.   

    好,收到。我测试一下,成功立即给分结贴
    bzszp(SongZip) 和  zhpsam109(孤寂无边) :能不能稍微注释一下
      

  3.   

    zhpsam109(孤寂无边) 的语句拼写错误
    :)
    select sum(decode(xb,'女',1,0))/count(xm) from tablename;
      

  4.   

    呵呵,没有啦,decode() not decoed()
      

  5.   

    版主没有蒙你啊,你把decode 拼成了decoed了。
      

  6.   

    呵呵:)就是写错了,zhpsam109(孤寂无边)老兄
      

  7.   

    bzszp(SongZip) 和  zhpsam109(孤寂无边)(纠正拼写后)的回答都是正确的,多谢了。但是能不能写个注释到这个帖子上。俺还是数据库方面的生手
      

  8.   

    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应该可以看明白了吧。
      

  9.   

    先求出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;
      

  10.   

    如果使用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