mysql - 如何更新学生成绩的联结表中的行
问题描述
我又来了。非常感谢您的帮助。
这是我关于如何在连接表中选择和显示学生成绩的老问题。
我成功地做到了,但现在我无法更新连接表中的成绩。
这是我的示例表。
"student"
-----------------------
|studentID | FullName |
-----------------------
|1234 | John |
|1235 | Michael |
|1236 | Bryce |
"subject_bsit"
-----------------------------------
|subject_id| subject_name |grade |
-----------------------------------
| 1 | Programming | 3 |
| 2 | Networking | 2.5 |
| 3 | Algorithm | 1.75|
| 4 | Physical Educ | 2 |
This is the Junction table to connect the
two now.
"student_subject"
----------------------------
| student_id | subject_id |
----------------------------
| 1235 | 1 |
| 1235 | 2 |
| 1235 | 3 |
| 1234 | 1 |
这是我所做的查询。这是一个示例,我试图更新 具有subject_id = 1的studentID 1235的成绩
更新 3:
sql = "UPDATE student_subject " & _
" INNER JOIN subject_bsit " & _
" ON subject_bsit.subject_id = student_subject.sub_id " & _
" SET grade = 1 " & _
" where student_subject.student_id='" & Txtbox.Text & "' AND student_subject.sub_id = 1"
& Txtbox.Text & 是用户输入学生身份的地方,不要介意。非常感谢我使用 Visual studion vb.net。
这是我得到的确切错误。
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“FROM student_subject INNER JOIN subject_bsit ON subject_bsit.subject_id = studen”附近使用正确的语法
解决方案
您的查询不稳定,应该如下所示
UPDATE student_subject
INNER JOIN subject_bsit
ON subject_bsit.subject_id = student_subject.sub_id
SET grade=?
where student_subject.student_id='" & Txtbox.Text & "' AND student_subject.sub_id = 1
推荐阅读
- yocto - 如何在 yocto 图像中引入 php5?
- delphi - Delphi:带有 SSL 证书文件的 TWebBrowser?
- python - 如何理解 python 中的 re.sub("", "-", "abxc")
- docker - “无法访问此站点”(非常简单的 docker 指令)
- azure-service-fabric - 使用 X509 证书创建安全的独立服务结构集群
- asp.net-core-2.1 - Asp Net Core 2.1 - 我们可以在启动 ctor 中使用 ConfigurationBuilder 吗?
- php - Onesignal 徽章计数增量不起作用
- web-services - 是否需要在 Web 服务客户端的 Configuration 类中定义 client.setDefaultUri
- unity3d - 静态库的文件名可以重命名吗
- android - 如何在片段本身中使用 DialogFragment 在 Android 中进行文本输入