接任务,赚取用不完的金币中国教程网
《Photoshop专家讲堂》光盘热售
参与论坛活动,快速赚取金币精品素材,中英文字体
发新话题
打印

试题类型:分类汇总问题请教

试题类型:分类汇总问题请教


试题类别表classlist的结构说明:
id title depth rootid parent
1 领导能力 0 1 0
         
2 领导艺术 1 1 1
         
3 沟通能力 1 1 1
         
4 激励技巧 1 1 1
         
5 授权能力 1 1 1
         
6 组织管理 0 6 0
         
7 组织设计 1 6 6
         
8 用人能力 1 6 6
         
9 团队建设 1 6 6
         
10 战略决策 0 10 0
         
11 战略管理 1 10 10
         
12 决策能力 1 10 10
         
13 控制执行 0 13 0
         
14 绩效管理 1 13 13
         
15 目标管理 1 13 13
         
16 时间管理 1 13 13
         
17 社交谈判 0 17 0
         
18 交际能力 1 17 17
         
19 谈判能力 1 17 17
         
20 创新能力 0 20 0
         
21 创新能力 1 20 20
试题表news
id          int           
title       nvachar         试题内容
class       int             试题类别,对应classlist中的id
tjnews      int             1为选择题,0为问答题
hotnews     int             试题期数

答案表answer
id          int
subject     nvachar         答案选项内容
stid        int             对应试题题号
score       decimal         本选项分值

答题记录表grade
id          int
username    nvarchar        答题人
stid        int             试题题号,对应news表中id
anid        int             选择项,对应amswer表中id,
score       decimal         本选择的得分
class       int             试题类别,对应classlist中id
item        int             试题期数,对应news表中hotnews

假设已经将答题情况录入到grade表中,现在想统计一下每个答题人这一期试题的总分、实际得分(已解决),各小类试题的总分和实际得分(已解决),各大类题的总分和实际得分,即这里的:
领导能力    实际得分
            应得总分
组织管理    实际得分
            应得总分
战略决策    实际得分
            应得总分
控制执行    实际得分
            应得总分
创新能力    实际得分
            应得总分

declare @username nvarchar(20)
set @username='...'

select
    a.title,
    isnull(sum(c.u_score),0) 实际得分,
    isnull(sum(c.m_score),0) 应得总分
from
    (select * from classlist where parent=0) a
inner join
    (select * from classlist where parent!=0) b
on
    a.id=b.parent
left join
    (select class,
         (select max(score) from answer where stid=news.id) m_score,
         (select s.score from grade g,answer s where g.stid=s.stid and g.anid=s.id and g.stid=news.id and g.username=@username) u_score
     from news)c
on
    b.id=c.class
group by
    a.id,a.title
order by
    a.id
发新话题 返回列表