我正在处理一个select语句,该语句应该返回每个上课日的课程。在周期重新开始前有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语句返回一个空行(带有空值)来代替某一天关闭的句点。我尝试添加Unions,将当天作为唯一值。
这不起作用,因为我得到前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
感谢您提供的任何帮助!
答案 0 :(得分: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