SQL SQL抽取兩年度全年平均分進步值

本文由 新丁9號 在 2023-10-27 發表於 "WebSAMS 討論區" 討論區

  1. 10399535

    新丁9號
    Expand Collapse

    文章:
    38
    讚:
    0
    求指教,嘗試用以下SQL抽資料,但只能抽到S4-S6的學生成績,但S2-S3是空的,解決不了,請指教,謝謝!

    select
    a.CLASSCODE,
    a.CLASSNO,
    b.CHNAME,
    c.SYSPERCSCORE '前年度全年平均',
    d.SYSPERCSCORE '上年度全年平均',
    (case when d.SYSPERCSCORE is null then 0 else d.SYSPERCSCORE end) - (case when c.SYSPERCSCORE is null then 0 else c.SYSPERCSCORE end) '相差值'
    from wsadmin.VW_STU_LATESTSTUSCHREC a
    join wsadmin.TB_STU_STUDENT b
    on a.SUID = b.SUID and a.STUID = b.STUID and a.SCHYEAR =? and a.CLASSLVL = ?
    join wsadmin.TB_ASR_STUDASSESSDATA c
    on a.SUID = c.SUID and a.STUID = c.STUID and c.SCHYEAR=(a.SCHYEAR-1) and c.TIMESEQ = 1000
    join wsadmin.TB_ASR_STUDASSESSDATA d
    on a.SUID = d.SUID and a.STUID = d.STUID and a.SCHYEAR = d.SCHYEAR and d.TIMESEQ = 1000
    order by 6 desc
     
    #1 新丁9號, 2023-10-27
  2. 58521906

    edb-catherinewschan
    Expand Collapse

    文章:
    310
    讚:
    0
    你好,

    用 VW_STU_LATESTSTUDENT 就可以抽取到每位學生曆年記錄,另外要用left outer join ,而不要只用JOIN。

    請試試以下的SQL

    select
    a.CLASSCODE,
    a.CLASSNO,
    a.CHNAME,
    c.SYSPERCSCORE '前年度全年平均',
    d.SYSPERCSCORE '上年度全年平均',
    (case when d.SYSPERCSCORE is null then 0 else d.SYSPERCSCORE end) - (case when c.SYSPERCSCORE is null then 0 else c.SYSPERCSCORE end) '相差值'
    from wsadmin.VW_STU_LATESTSTUDENT a
    left outer join wsadmin.TB_ASR_STUDASSESSDATA c
    on a.SUID = c.SUID and a.STUID = c.STUID and c.SCHYEAR=(a.SCHYEAR-1) and c.TIMESEQ = 1000
    left outer join wsadmin.TB_ASR_STUDASSESSDATA d
    on a.SUID = d.SUID and a.STUID = d.STUID and a.SCHYEAR = d.SCHYEAR and d.TIMESEQ = 1000
    where a.SCHYEAR=? and a.CLASSLVL=?
    order by 6 desc
     
    #2 edb-catherinewschan, 2023-10-30
    Last edited: 2023-10-31
  3. 10399535

    新丁9號
    Expand Collapse

    文章:
    38
    讚:
    0
    你好,跟你的加了
    left outer join,但Lower form仍是沒結果,付圖。另高班多了些不明行!!
     
    #3 新丁9號, 2023-10-31
  4. 10399535

    新丁9號
    Expand Collapse

    文章:
    38
    讚:
    0
    付圖參考
     

    附件文件:

    • 00001.jpg
      00001.jpg
      文件大小:
      349.6 KB
      瀏覽:
      25
    #4 新丁9號, 2023-10-31
  5. 58521906

    edb-catherinewschan
    Expand Collapse

    文章:
    310
    讚:
    0
    你好

    如果前年沒有平均分,就會顯示空白。 你可以用 學生資料 > 學生概況 > 搜尋學生,找到了學生之後,
    再看 在學資料 ,查一下學生上年的班別學號,再走到 學生成績 > 查詢 > 學生成績 去查一下成績。
    如果學生是插班生,就會沒有前學年的平均分了。

    另外,若果用JOIN,就是INNER JOIN,這樣只會顯示出有前年度及上年度的分數。
     
    #5 edb-catherinewschan, 2023-11-02
  6. 58521906

    edb-catherinewschan
    Expand Collapse

    文章:
    310
    讚:
    0
    Lower form 是否入分數,還是入GRADE??
     
    #6 edb-catherinewschan, 2023-11-02
  7. 10399535

    新丁9號
    Expand Collapse

    文章:
    38
    讚:
    0
    發現用
    發現用報表
    [FONT=Arial, Helvetica, sans-serif]"班總積分及等級表 (R-ASR029-C)"低form
    年終資料是沒有了平均分高form有。
    [/FONT][FONT=Arial, Helvetica, sans-serif]做了consolidation 的
    真有些迷惘!![/FONT]
     
    #7 新丁9號, 2023-11-03
  8. 58521906

    edb-catherinewschan
    Expand Collapse

    文章:
    310
    讚:
    0
    建議你先到學生成績 > 查詢 > 學生成績 去查一下成績 , 看看有沒有平均分。如果沒有平均分,就要做一次數據整合,再看看有沒有平均分。 因為 無論你 出報表 或是 用SQL抽取資料,在 學生成績 > 查詢 > 學生成績 都應該有顯示分數。
     
    #8 edb-catherinewschan, 2023-11-03