我有四個值表:教師,認證,block_subjects和塊以及兩個關係表:instructor_certifications和subject_certification。就像這樣:加入兩個多對多關係,'all'operator
block -- block_subject
|
|
subject_certification
|
|
certification
|
|
instructor_certification
|
|
instructor
我想要一個查詢,會告訴我,每個塊,其中教官師資塊。具體來說,我不想指定塊ID作爲查詢的一部分;我想根據不同的標準選擇多個塊。
這裏是(非工作)查詢我目前有:
select inst.name, inst.id
from instructor as inst
join instructor_certification as ic on inst.id = ic.instructor_fid and
ic.certification_fid = all (
select cert.id
from block_subject as bs
join subject_certification as bsc on bsc.block_fid = bs.id
join certification as cert on bsc.certification_fid = cert.id
where bs.id = any (
select bs.id
from block as b
join block_subject as bs on b.subject_fid = bs.id
where (b.start_date, b.end_date) overlaps (?, ?)
)
)
顯然,這並不工作,因爲「所有」收集所有在日期範圍內的所有block_subject所需的認證。
編輯:另外我應該澄清,實際上,每個block_subject需要多個認證。
聽起來像你對我要求的關係運算符是[師](http://www.simple-talk.com/sql/t-sql-編程/劃分我們的關係SQL的分支/):「提供所有部分的供應商」 - >「可以教授塊上所有主題的教師」,或許? – onedaywhen 2011-05-20 06:09:04
這看起來像我需要的......哦,從來沒有真正採取數據庫類的樂趣。 – gibbss 2011-05-20 06:51:47
好的,我將其更改爲新的要求。 – Hogan 2011-05-20 10:15:09