python - 使用内部连接和 where 条件更新
问题描述
我正在研究 MySQL 并创建了两张表,一张用于students_data
,一张用于Attendance_details
Attendance table
有学生 ID 的 FK 这是Attendance table
AttID, ID, DateTime, Statues
还有students_data
桌子
fname, lname, ID
ABN , AA , 123
我的问题:
我想Attendance_details
根据学生 ID 更新表格,如下面的查询
sql = " UPDATE Attendance_table INNER JOIN students_data ON Attendance_table.ID=students_data.ID SET Attendance_table.ID=students_data.ID , Statues=%s , DateTime=%s , WHERE students_data.fname = %s"
val=(1,formatted_date,name)
mycursor.execute(sql,val)
mydb.commit()
我有一个错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE students_data.fname = 'ABN''
注意:我正在从事人脸识别项目,其中所有人脸都有一个预定义的名称,并将其与人脸进行比较,students_data
因此名称 ABN 是从人脸中读取的 :)
任何帮助或建议!
解决方案
你在 where 之前使用了一个额外的逗号
DateTime=%s , WHERE students_data.fname = %s"
去掉这个逗号。您的代码应该是:
sql = " UPDATE Attendance_table INNER JOIN students_data ON Attendance_table.ID=students_data.ID SET Attendance_table.ID=students_data.ID , Statues=%s , DateTime=%s WHERE students_data.fname = %s"
推荐阅读
- json - 无法使用 Google 存储桶中的 Biquery 解析 JSON
- javascript - 使用 Javascript 在 CSS 中添加随机背景图像
- wordpress - 我如何在 elementor 中执行此操作,需要创建更改部分的排序下拉列表
- node.js - amqplib@0.4.2 node-red-contrib-amqp#installation 不支持的引擎
- css - 在 Sitecore 富文本编辑器中使用自定义 CSS 样式
- office-js - Outlook 脚本实验室:对象不支持默认示例“创建新约会”上的属性或方法“addHandlerAsync”
- excel - 合并单元格的 Excel 过滤 - 扩展
- c - S_ISDIR() 和 S_ISREG() 只能在当前目录中正常工作?
- sql - 我可以(在多对多关系中)仅选择 A 列中与 B 列中的所有 id:s 有连接的那些 id:s 吗?
- python - pytesseract 检测到错误的整数值