sql - 如何从三个表中提取行
问题描述
我知道问这个问题是不合适的。
学生表 - ID、姓名、GPA
班级表 - ID、职务、学期
Student_Class 表 - Student_ID、Class_ID、Student_Grade
从这个表结构中,如何提取参加 class.title = 'MATH101' 和 class.semester = 'FALL2018' 的学生姓名。
没有太多研究,我不得不问这个问题。我怎样才能开始呢?
解决方案
Student_Class
Student
是连接表,它实现和之间的多对多关系Class
。所以它只需要加入Student_Class
with Student
onstudent_id
和Student_Class
with Class
on class_id
。
select s.name
from Student s inner join Student_Class cs on s.id = cs.student_id
inner join Class c on cs.class_id = c.id
where c.title = ‘MATH101’ and c.semester = ‘FALL2018’.
推荐阅读
- java - 使用 maven 插件无效凭据将 Java 部署到 Heroku
- python - 如何使用python查找和删除损坏的文件
- jestjs - 当 Jest 位于 node_modules 中时,它不会解析 TypeScript 配置文件
- apache-flink - Flink SQL Savepoint 在 sql-client.sh 中不起作用
- python - 悬停时为画布形状添加轮廓?
- javascript - 无法访问事件处理程序方法中的全局变量(javascript)
- mysql - 为什么作者使用了内连接而不是左连接?
- graphql - GraphQL 那么是否可以根据查询参数确定将动态返回的类型?
- django-rest-framework - DRF 序列化继承模型
- clang - 什么是 LLVM X 射线修补?