select classid 班级,
count(*) 学生数量
sum(decode(state,4,1,0)) 优秀
from YourTablename
group by classid;

解决方案 »

  1.   

    select a.classid ,sum(a.studentid) studen_sum,sum(b.studentid) from school a,(select * from school where state = '4') b where a.id += b.id group by a.classid;
      

  2.   

    请问sum(decode(state,4,1,0))这又是什么意思呢。
      

  3.   

    sum(decode(state,4,1,0))其中decode(state,4,1,0)是检查state字段的值如果是4的话函数就返回1其他数值则返回0