我正在研究一个选择语句,该语句应该返回每个上学日的类。在周期重新开始之前有 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
感谢您提供的任何帮助!
如果您所说的是您希望每个学生有 4 行,那么应该像下面这样的事情就可以了。
SELECT
B.course
A.school_cycle_day,
B.legal_first_name,
B.legal_surname,
B.room_no
FROM
(
SELECT '1' AS school_cycle_day
FROM DUAL
UNION ALL
SELECT '2'
FROM DUAL
UNION ALL
SELECT '3'
FROM DUAL
UNION ALL
SELECT '4'
FROM DUAL
) A
LEFT JOIN
(
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')
) B ON A.school_cycle_day = B.school_cycle_day