我需要SQL查询的帮助。它似乎工作,但我需要做两个改变:
1)如果学生没有任何缺席,它不应该为他显示一行,但它似乎没有响起。 2)如果我想显示学生从一组课程中注册的课程,那么哪种课程是正确的?
SELECT DISTINCT
s.student_number AS "Student Number",
s.lastfirst AS "Student Name",
DECODE(s.grade_level,-1,'PK',0,'KG',s.grade_level) AS GRADE,
s.home_phone AS "Phone",
DECODE(s.schoolid,280050,'Kodiak High School',s.schoolid) School,
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='1') AS "Per. 1",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='2') AS "Per. 2",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='3') AS "Per. 3",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='4') AS "Per. 4",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='5') AS "Per. 5",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='6') AS "Per. 6",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='7') AS "Per. 7",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='8') AS "Adv",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='9') AS "Act",
(SELECT listagg(attm.att_code,'|') within group (order by attm.att_code) FROM pssis_attendance_meeting attm WHERE attm.att_date=to_date(SYSDATE) AND attm.studentid=s.id AND attm.att_code IS NOT NULL AND attm.period_number='10') AS "Clb"
FROM attendance att
JOIN students s ON s.id=att.studentid
JOIN cc ON s.ID=cc.studentid
JOIN sections ON cc.sectionid = sections.id
WHERE
att.att_date=to_date(SYSDATE)
AND att.schoolid in ('280050')
AND s.enroll_status='0'
AND cc.termid = 2700
AND sections.course_number LIKE 'ACT%'
ORDER BY s.lastfirst