【发布时间】:2018-05-11 00:00:06
【问题描述】:
我需要最低/最高分数,还需要获得这些分数的日期。关于如何使用 Oracle SQL 做到这一点的任何想法?这是完整的代码,它给了我学生的名字等,以及最低分数和 1 个最高分数:
SELECT s.lastfirst, s.state_studentnumber, s.grade_level, s.schoolid,
MIN(case when ts.name='ACT_English' then sts.numscore else null end) ACT_English,
MIN(case when ts.name='ACT_Reading' then sts.numscore else null end) ACT_Reading,
MIN(case when ts.name='ACT_Math' then sts.numscore else null end) ACT_Math,
MIN(case when ts.name='ACT_Science' then sts.numscore else null end) ACT_Science,
MAX(case when ts.name='ACT_Composite' then sts.numscore else null end) ACT_Composite
FROM studenttestscore sts
INNER JOIN students s
ON sts.studentid=s.id
INNER JOIN studenttest st
ON sts.studenttestid=st.id
INNER JOIN testscore ts
ON sts.testscoreid=ts.id
INNER JOIN test t
ON ts.testid=t.id
WHERE t.name='ACT' AND s.enroll_status=0 and s.schoolid = 32
GROUP BY s.lastfirst, s.state_studentnumber, s.grade_level, s.schoolid
ORDER BY s.lastfirst
日期字段位于 studenttest 表 (st.test_date) 中。 提前谢谢...
【问题讨论】:
-
仅供参考,您可以在
CASE语句中省略else null。 -
了解表的结构可能会有所帮助
-
@ValerioSantinelli 这里是示例表结构:学生表有这些字段:lastfirst、student_number、id。 studenttestscore 表有 studentid(链接到 students.id)、numscore、studenttestid、testscoreid。 studenttest 表有 id(链接到 studenttestscore.studenttestid),test_date。 testscore 表有 id(链接到 studenttestscore.studenttestid)、name、testid。测试表有id(链接到testscore.testid),名字。这很复杂,我知道,但这就是 PowerSchool 的设置方式,没有控制......