我正在编写一个选择语句,该语句应该返回每个上学日的课程。在周期重新开始之前有 4 个上课日。(例如,星期一 = 第 1 天,星期二 = 第 2 天...星期四 = 第 4 天,星期五 = 第 1 天..等)
有些学生可能在某些日子有 1 个休息日,在这种情况下,我们应该在该天/期间组合显示一个空白区域。
目前,select 语句只返回有值的天数。
例子:
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
我想要完成的是让 select 语句返回一个空行(具有空值)来代替某一天关闭的时间段。我尝试添加以天为唯一值的工会。
这不起作用,因为我得到了前 3 行,然后是其他 4 行,但我真正想要的是前 3 行(例如第 1、3、4 天)和最后一个联合行(例如第 2 天)在这种情况下,我可以在当天下订单。
我怎样才能做到这一点?我应该使用相交吗?..或相交的反面?这也适用于 Oracle 数据库。
选择语句:
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;
输出:
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
感谢您的任何帮助,您可以提供!