【发布时间】:2019-03-23 04:21:19
【问题描述】:
对不起,我提出了另一个问题,因为我的最后一个问题太混乱了。
编辑:我当前的查询
UPDATE student_subject
JOIN subject_bsit
ON subject_bsit.subject_id = student_subject.sub_id
SET enrolled = 1
where student_subject.student_id = 1235
and student_subject.sub_id = 1
我想要发生的是。
Student_id=1235 正在尝试注册 subject_id=5,因此该声明不能发生,因为 subject_id=5 具有 的先决条件>subject_id=1 或编程 1
但如果 student_subject 中的示例 sub_id 为 1 且 Enrolled=1 表示学生完成编程并且现在已经注册,那么 student=1235 现在可以注册 subjectid=5
我不知道如何进行此查询。非常感谢。
THIS IS THE TABLE
"student"
-----------------------
|studentID | FullName |
-----------------------
|1234 | John |
|1235 | Michael |
|1236 | Bryce |
"subject_bsit"
-----------------------------------------
|subject_id| subject_name | pre_id |
-----------------------------------------
| 1 | Programming 1 | 0 |
| 2 | Networking | 0 |
| 3 | Algorithm | 0 |
| 4 | Physical Educ | 0 |
| 5 | Programming 2 | 1 |
This is the Junction table to connect the
two now.
"student_subject"
------------------------------------------------
| student_id | subject_id | Grade | Enrolled |
------------------------------------------------
| 1235 | 1 | 0 | 0 |
| 1235 | 2 | 0 | 0 |
| 1235 | 3 | 0 | 0 |
| 1234 | 1 | 0 | 0 |
【问题讨论】:
-
想想你想要得到什么。您想要来自
student_subject的记录,其中student_id与您的学生匹配,Enrolled为1,subject_id等于subject_bsit的pre_id,其中subject_id是主题你想注册。如果你在编写 SQL 查询时遇到问题,那通常是因为你不清楚查询必须做什么,所以先解决这个问题。拿起笔和纸,用简单的语言写下来。然后你可以编写代码来一点一点地实现它。 -
嗨,我已经有了我的 SQL 查询,但是由于联结表和太多的连接我遇到了问题,我会用我的查询更新它。
-
并删除您的一个或其他问题。
标签: mysql sql database vb.net phpmyadmin