求一sql文 急急急!!!

jinsuo_1986 2010-07-23 10:45:37
我要在全年级学生中按照班级分组查找每班数学成绩及格的学生数和每班学生总数,假设现有表如下:
学号 班号 数学成绩 。。。
10001 001 50。。。
10002 001 60。。。
10003 002 70。。。
...全文
79 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dota_noney 2010-07-23
  • 打赏
  • 举报
回复
select 班号,count(1) 每班学生总数,
count(case when 数学成绩>=60 then 1 end) 数学成绩及格的学生数
from tb
group by 班号
czfxwpy 2010-07-23
  • 打赏
  • 举报
回复
如楼上。不过我喜欢sum
select 班号,count(1) 每班学生总数,
sum(case when 数学成绩>=60 then 1 else 0 end) 数学成绩及格的学生数
from tb
group by 班号
心中的彩虹 2010-07-23
  • 打赏
  • 举报
回复
[Quote=引用楼主 jinsuo_1986 的回复:]
我要在全年级学生中按照班级分组查找每班数学成绩及格的学生数和每班学生总数,假设现有表如下:
学号 班号 数学成绩 。。。
10001 001 50。。。
10002 001 60。。。
10003 002 70。。。
[/Quote]

select 班号,count(1) 每班学生总数,
count(case when 数学成绩>=60 then 1 end) 数学成绩及格的学生数
from tb
group by 班号
Phoenix_99 2010-07-23
  • 打赏
  • 举报
回复
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

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧