I'm working on a select statement that should return the class for each of the school days. There are 4 school days before the cycle starts over again. (e.g. Monday = Day1, Tuesday = Day2...Thursday = Day4, Friday = Day1..etc )
Some students may have 1 period off on certain days, in which case we should display an empty space on that day/period combination.
At the moment, the select statement only returns days which have a value.
Example:
Day 1 Day 2 Day 3 Day 4
Period 1 class class off class
Period 2 class class class off
Period 3 off class class class
Period 4 class off class class
What I'm trying to accomplish is to have the select statement return an empty row (with null values) in place of the period that is off on a certain day. I tried adding Unions with the day as the only value.
This isn't working as I'm getting my first 3 rows and then the 4 others, but what I actually want is the first 3 rows (e.g. with the days 1,3,4) and the last union'ed row (e.g. day 2) in which case I can then afterwards do an order by on the day.
How can I do this? Should I be using an intersect? ..or the opposite of an intersect? Also this is for an Oracle database.
Select statement:
select spct.course_code||'-'||spct.course_section as course,t.school_cycle_day as jour,p.legal_first_name,p.legal_surname,sc.room_no
from student_program_class_tracks@trl spct,class_meetings@trl cm,school_classes@trl sc,persons@trl p,timeslots@trl t,school_timeline_periods@trl tsp
where spct.school_code=cm.school_code
and spct.school_code=sc.school_code
and spct.school_code=t.school_code
and spct.school_code=tsp.school_code
and spct.school_year=cm.school_year
and spct.school_year=sc.school_year
and spct.school_year=t.school_year
and spct.school_year=tsp.school_year
and t.school_year_track=tsp.school_year_track
and t.school_timeline_code=tsp.school_timeline_code
and t.school_period=tsp.school_period
and spct.class_code=cm.class_code
and spct.class_code=sc.class_code
and sc.reporting_teacher=p.person_id
and cm.block=t.block
and spct.school_code='73'
and spct.school_year='20122013'
and spct.person_id='000170629'
and cm.semester='2'
and cm.term='1'
and t.school_period='1'
and ((spct.start_date <= sysdate and spct.end_date >= sysdate) or spct.demit_indicator='0')
--order by t.school_cycle_day
UNION
SELECT '','1','','','' from DUAL
UNION
SELECT '','2','','','' from DUAL
UNION
SELECT '','3','','','' from DUAL
UNION
SELECT '','4','','','' from DUAL;
Output:
Course Jour Legal_first_name Legqal_surname Room_no
PPL4OO-03 2 François Belle-Isle 1-139
SBI4UU-02 4 Louise Bérubé 1-155
TFC4EE-02 3 Gino Proulx 1-127
1
Thanks for any help you can provide!