SQL T4與T2分別找出中文、英文、數科的最進步成績學生排名

本文由 Fiona 在 2019-10-20 發表於 "WebSAMS 討論區" 討論區

標籤:
  1. 55040725

    Fiona
    Expand Collapse

    文章:
    8
    讚:
    0
    請問應如何提取學生成績,請指教,謝謝:
    同年度內,一至五年級,以T4與T2對比,分別找出中文科(以總分計)、英文科(以總分計)、數學科,分別這三科的學生「進步成績」及「級內科目的進步排名」;
    而六年級,則是T1與T3對比。
     
  2. 58521906

    edb-catherinewschan
    Expand Collapse

    文章:
    302
    讚:
    0
    你好,

    可以參考一下 , 網上校管系統 — 常用SQL參考庫, 網址是
    https://www.websams.edb.gov.hk//sql/html/SQL_Q&A.html#

    在 學生成績 (下載), 當中第5條題目比較接近你的問題

    5. 比較下學期期中考(1201)科目名次與下學期期考(1202)中英數常名次,每班科目名次進步最多者,以便列出中/英/數/常進步獎名單。

    可以參考一下SQL, 把考績 1201 和 1202 改為 1400 (即T4) 和 1200(即T2) , 再把班名次(omclass) 變為級名次(omclasslvl) , 另外再加入科目分數(sysscore)做比較


    我也嘗試把SQL改了,請試試...

    select
    a.CLASSCODE '班別',
    a.CLASSNO '學號',
    a.CHNAME '姓名',
    d.ch_des '科目',
    b.sysscore '今年T4 成績',
    c.sysscore '今年T2 成績',
    (case when b.syspercscore is null then 0 else b.syspercscore end) - (case when c.syspercscore is null then 0 else c.syspercscore end) '進步 T4-T2',
    b.omclasslvl 'T4級內科目排名',
    c.omclasslvl 'T2級內科目排名',
    (case when c.omclasslvl is null then 0 else c.omclasslvl end) - (case when b.omclasslvl is null then 0 else b.omclasslvl end) 'Diff',
    (case when Diff<=0 then null else Diff end) '級內科目的進步排名'
    from wsadmin.VW_STU_LATESTSTUDENT a
    left outer join wsadmin.tb_asr_subjassessdata b
    on a.suid=b.suid and a.schlvl=b.schlevel and a.schsess=b.schsession and a.classlvl=b.classlevel and a.schyear=b.schyear and a.stuid=b.stuid and b.timeseq=1400 and b.subjcode in ('080', '165', '280')
    left outer join wsadmin.tb_asr_subjassessdata c
    on a.suid=c.suid and a.schlvl=c.schlevel and a.schsess=c.schsession and a.classlvl=c.classlevel and a.schyear=c.schyear and a.stuid=c.stuid and b.subjcode=c.subjcode and c.timeseq=1200
    left outer join wsadmin.tb_hse_common d
    on a.suid=d.suid and b.subjcode=d.code_id and d.tb_id='SBJ'
    where a.classlvl=? and a.schyear=?
    order by a.schlvl, a.schsess, a.classlvl, a.classcode, a.CLASSNO, a.chname, b.subjcode
     
    #2 edb-catherinewschan, 2019-10-23