select count(distinct 学生专业) from 表
得到所有专业数select count(distinct 学生专业) from 表 where 学生姓名='张三'
得到“张三”所学专业数后者除以前者就是结果

解决方案 »

  1.   

    如果是ORACLE:
    select (select count(distinct 学生专业) from 表 where 学生姓名='张三')/(select count(distinct 学生专业) from 表) from dualdual是ORACLE中的系统临时表
      

  2.   

    我想在同一个查询里实现
    select StudentName,StudentSex,"百分比"=(count(StudentZY))/(count(distinct Studentzy))
    from StudentJBQK
    Where StudentSex='woman'
    group by StudentName,StudentSex这个方法不对.以下是结果
    学生名  性别       百分比                          
     A1    woman      1
     Q1    woman      1
      

  3.   

    当然不对了,你的count(StudentZY)和count(distinct Studentzy)都被Where StudentSex='woman'限定了;并且前者肯定大于或等于后者。我的第二个回答就是在一个查询里实现
      

  4.   

    oracle_lover(数据库情人) 你说的不对,我想要的功能是:性别是女生的,学的专业占全部专业的百比分.不用你第一种的方法,select Studentid,"百分比"=(select count(distinct studentzy) from studentJBQK where Studentsex='woman')/(select count(distinct Studentzy) from studentJBQK)
    from studentJBQk执行之后百分比都为,0
      

  5.   

    在我这里执行相同的语句(字段名,表名不同,结构完全一样),结果正确
    select nf,(select count(distinct bm) from qgb_bggz where bm='物资部')/(select count(distinct bm) from qgb_bggz) from qgb_bggz;你分别测试一下两个子查询,看结果对不对
      

  6.   

    我也执行了,结果为0.还是不对.
    select "百分比"=(select count(distinct StudentZy) from studentJBQK where studentsex='woman')/(select count(distinct studentzy) from studentJBQK)
      

  7.   

    我是说你分别测试一下
    select count(distinct StudentZy) from studentJBQK where studentsex='woman'select count(distinct studentzy) from studentJBQK