好的,我有两张桌子。
1列出了一系列课程及其详细信息。1列出了一系列课程及其关联关系。
我需要创建一个查询,该查询将列出课程名称,列出所有课程,然后指示课程是否在课程中(TRUE)或不存在(FALSE)。
这是我到目前为止所尝试过的。
课程表的左外连接,因为我希望所有的课程与课程进行比较
计算每个课程的课程IN数-不起作用仅返回'1‘值;并且仅显示课程中的课程
查找两个表之间的差异-不起作用,只显示没有课程的值。
尝试IIF(为空)计算-不起作用只返回'TRUE‘值;并且只显示课程中的课程。
这应该很简单。有人能帮我创建查询吗。基本上,我需要两个表中的所有值都显示出来,然后显示与课程相关的值为空的位置。
表1:
COURSE ID COURSE NAME
1 ENGLISH
2 FRENCH
3 DRAWING
4 SKETCHING表2
Curriculum ID Curriculum NameID Course ID
1 Senior (actually #) 1
2 Senior 3
3 Junior 1
4 Junior 2
5 Junior 3结果
Curriculum Name Course Name In Curriculum
Senior English True
Senior French False
Senior Drawing True
Senior Sketching False
Junior English True
Junior French True
Junior Drawing True
Junior Sketching FalseTJ
发布于 2020-09-05 07:00:23
由于课程和课程之间本质上是多对多的关系(一个课程可以出现在多个课程上,一个课程可以包含多个课程),我建议用以下方式组织数据:
表:课程
+-------+-----------+
| Co_ID | Co_Desc |
+-------+-----------+
| 1 | English |
| 2 | French |
| 3 | Drawing |
| 4 | Sketching |
+-------+-----------+表:课程
+-------+---------+
| Cu_ID | Cu_Desc |
+-------+---------+
| 1 | Junior |
| 2 | Senior |
+-------+---------+连接表: Curriculum_Courses
+----------+----------+
| CC_Cu_ID | CC_Co_ID |
+----------+----------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 3 |
+----------+----------+然后,您的查询相对容易构造,因为您可以通过以下方式使用交叉连接和左连接的组合:
select
t.cu_desc as [Curriculum Name],
t.co_desc as [Course Name],
not cc_cu_id is null as [In Curriculum]
from
(select * from curriculums, courses) t left join curriculum_courses u on
t.cu_id = u.cc_cu_id and
t.co_id = u.cc_co_id
order by
t.cu_id, t.co_idhttps://stackoverflow.com/questions/63742689
复制相似问题