有一个表字段:学号,姓名,课程,成绩,班级如何在一条语句中查询某班某课程总人数和该课程及格人数?
即:select count(*) 总人数,(???) 及格人数 from cjb where bjmc='班级名称' and kcmc='课程名称'
请问上面红色标记的部分该怎么写?
谢谢!!!

解决方案 »

  1.   

    select count(*),(select count(*) from cjb b where b.bjmc='班级名称' and b.kcmc='课程名称' and a.xh=b.xh) from cjb a where a.bjmc='班级名称' and a.kcmc='课程名称'这种写法太差劲!
      

  2.   

    select 
    (select cout(*) from cjb where bjmc='班级名称' and kcmc='课程名称'),
    (select cout(*) from cjb where bjmc='班级名称' and kcmc='课程名称' and cj>=60)
    from dual这种方式也不行,因为我的where后面的内容太多!
      

  3.   

    select count(*) 总人数,count(case when 成绩>=60 then 1 else 0 end) 及格人数 
    from cjb where bjmc='班级名称' and kcmc='课程名称'
      

  4.   


    select count(*) 总人数,sum(case when 成绩>=60 then 1 else 0 end) 及格人数  
    from cjb where bjmc='班级名称' and kcmc='课程名称'
      

  5.   


    你的用count  要这样
    count(case when 成绩>=60 then 1  end) 及格人数 
      

  6.   

    还有没其它的写法?
    如果case 条件复杂了能不能这么写?
    如(case where xh(select xh from xsb where xb='男') then 1 else 0 end)?
      

  7.   

    (case where xh in(select xh from xsb where xb='男') then 1 else 0 end)?
      

  8.   

    (case when xh in(select xh from xsb where xb='男') then 1 else 0 end)?
    总是写错!该打!