ITPUB论坛 » Oracle开发 » Oracle Developer Suite » 分类统计数据如何处理?
12月微软Hyper-V虚拟化沙龙主题征集
2004-11-30 09:58 Arrayliuxs
分类统计数据如何处理?

目前有两个表,一个是学生表,包含名字,生日,班级。第二个是成绩表。
现在想按照出生的季度(未包含在生日内)和语文成绩(60以下,其他按照10分一级)作分类统计,我不知道有什么好的办法,目前唯一想到的是一条一条写,要写20条SQL查询,太繁琐。有没有简便的方法?
谢谢

2004-11-30 14:18 snowy_howe
因为还有情况不清,没法写sql。
思路为:出生的季度,要按生日所在季度来分组 to_char(birthday,'q')
语文成绩:首先60分之上,用substr(grade,-1)
                            60分之下,不分组
然后将两个sql用union连接。
你参考上述再考虑吧

2004-12-15 13:52 wlidflower
select case when b.score<60 then 60
       case when b.score>=60 and b.score<70 then 70
       case when b.score>=70 and b.score<80 then 80
       case when b.score>=80 and b.score<90 then 90
       else 100 end score,
       to_char(b.birthday,'yyyy') scoreyear
       to_char(b.birthday,'q') jidu
from student a,grades b
where
   a.student_id=b.student_id
and
   b.lesson_name='语文'  
group by scoreyear,jidu,score

页: [1]


Powered by ITPUB论坛