我有以下表格。表格class_students
与students
表格相关,因为它从那里获取student_id_column
数据。examination_data
有一列({ {1}})从class_student_id_column
表class_students
列获取数据。
student_id_column
student_id | student_names
1 ........................... ed
2 .......................... bravo
3 .........................某个名字
students
class_students_id | student_id_column | class_year
1 ................................... 2 .......... .................... 2000
2 ................................... 3 .......... .................... 2000
class_students
examination_data_id | class_students_id_column | php | jquery |绘制
1 ......................................... 1 .... ............................. 90 ..... 68 ............ 89 1 ......................................... 2 ....... .......................... 64 ..... 89 ............ 99
我想要更新表examination_data
并为行执行此操作,我希望我的where语句指向examination_data
列。
要做到这一点,我正在尝试这个
student_id
我的更新语句失败,因为表SELECT
examination_data.examination_data_id,
examination_data.class_students_id_column,
class_students.student_id_column,
students.student_id,
examination_data.php,
examination_data.jquery,
examination_data.drawing
FROM
examination_data
LEFT JOIN class_students ON (examination_data.class_students_id_column=class_students.class_students_id)
LEFT JOIN students ON (students.student_id=class_students.student_id_column)
UPDATE examination_data SET examination_data.jquery = 96 WHERE students.student_id = 2;
中没有students.student_id
列。我的另一个尝试是
examination_data
但是那很难打砖墙。
这是否可能,或者我必须在 UPDATE examination_data SET examination_data.jquery = l FROM students INNER JOIN ON students.student_id=... WHERE students.student_id = 2;
表中另外有student_id_column
吗?
答案 0 :(得分:2)
使用子查询:
UPDATE
examination_data
SET
jquery = 96
WHERE
class_students_id_column = (
SELECT class_students_id FROM class_students WHERE student_id_column = 2
)
答案 1 :(得分:0)
尝试此查询
UPDATE examination_data SET examination_data.jquery = 96 WHERE
examination_data.class_students_id_column =(
SELECT class_students_id FROM class_students WHERE student_id_column = 2);