我有三张桌子,我想在第一张桌子上看到来自其他人的价值观。让我解释一下:
课程表
+------------------+----------------+----------------+------------+-----------+
| LessonCode | SubjectCode | ClassCode | hour | day |
+------------------+----------------+----------------+------------+-----------+
| 1 | 10 | 1 | 15 | m |
| 2 | 11 | 2 | 20 | t |
| 3 | 12 | 3 | 30 | w |
+------------------+----------------+----------------+------------+-----------+
表类
+------------------+----------------+
| ClassCode | ClassName |
+------------------+----------------+
| 1 | Class1 |
| 2 | class2 |
| 3 | class3 |
+------------------+----------------+
表主题
+------------------+----------------+
| subjectCode | SubjectName |
+------------------+----------------+
| 10 | Maths |
| 11 | English |
| 12 | Greek |
+------------------+----------------+
我想在lesson
表格中插入SubjectName
和ClassName
列代替SubjectCode
和ClassCode
,并附上以下表格:< / p>
+------------------+----------------+----------------+------------+-----------+
| LessonCode | SubjectName | ClassName | hour | day |
+------------------+----------------+----------------+------------+-----------+
| 1 | Maths | Class1 | 15 | m |
| 2 | English | Class2 | 20 | t |
| 3 | Greek | Class3 | 30 | w |
+------------------+----------------+----------------+------------+-----------+
我该怎么办?
答案 0 :(得分:3)
这看起来像是JOIN
的工作! INNER JOIN
救援!
SELECT LessonCode, SubjectName, ClassName, hour, day
FROM lesson
JOIN class on lesson.ClassCode = class.ClassCode
JOIN subject on lesson.SubjectCode = subject.SubjectCode