我必须从一个已设置的表(“ student”,“ staff'”)中获取类型,并且根据结果,我必须更新staff或student_class_attendance表,我会尝试这样做
SELECT TYPE
CASE WHEN TYPE = 'staff' THEN
UPDATE staff_attendance SET statues = 1 WHERE staff_id = (SELECT type_id FROM rfid_details WHERE rfid_no = '124' )
WHEN TYPE = 'student' THEN
UPDATE student_class_attendance SET statues = 1 WHERE student_id = (SELECT type_id FROM rfid_details WHERE rfid_no = '124' )
END
FROM rfid_details WHERE rfid_no = '124'
还有
SELECT TYPE IF(TYPE = staff,
UPDATE staff_attendance
SET statues = 1
WHERE staff_id =
SELECT type_id
FROM rfid_details
WHERE rfid_no = '124' ,UPDATE student_class_attendance
SET statues = 1
WHERE student_id=
SELECT type_id
FROM rfid_details
WHERE rfid_no = '124' ) FROM rfid_details WHERE rfid_no = '124'
但显示
您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册,以在'CASE WHEN TYPE ='staff'THEN附近使用正确的语法 在第2行上更新staff_attendance SET雕像= 1在哪里
以及
您的SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,以获取在'IF(type = staff, 更新staff_attendance SET雕像= 1 在1号线的staff_i'
plz帮助解决此问题
答案 0 :(得分:0)
您根本无法在select语句中进行更新。您可以尝试以下操作:
UPDATE staff_attendance SET statues = 1 WHERE staff_id = (SELECT type_id FROM rfid_details WHERE rfid_no = '124' and type = 'staff');
UPDATE student_class_attendance SET statues = 1 WHERE student_id = (SELECT type_id FROM rfid_details WHERE rfid_no = '124' and type = 'student');