本帖最后由 jinsuo_1986 于 2010-07-23 10:49:45 编辑

解决方案 »

  1.   

    with temp as(
    select '10001' sno,'001' bno,50 score from dual
    union all
    select '10002' sno,'001' bno,60 score from dual
    union all
    select '10003' sno,'002' bno,70 score from dual
    )
    select bno,max(totalsum),max(avgsum) from (
    select bno,null totalsum,count(sno) avgsum from temp where score >=60 group by bno 
    union all
    select bno,count(sno) totalsum,null avgsum from temp group by bno
    )group by bno
      

  2.   


    select 班号,count(1) 每班学生总数,
    count(case when 数学成绩>=60 then 1 end) 数学成绩及格的学生数
    from tb
    group by 班号
      

  3.   

    如楼上。不过我喜欢sum
    select 班号,count(1) 每班学生总数,
    sum(case when 数学成绩>=60 then 1 else 0 end) 数学成绩及格的学生数
    from tb
    group by 班号
      

  4.   

    select 班号,count(1) 每班学生总数,
    count(case when 数学成绩>=60 then 1 end) 数学成绩及格的学生数
    from tb
    group by 班号