我有更新查询。但它显示sql错误
查询
Update ms_student set student_first_name=y.student_first_name,student_middle_name=y.student_middle_name,student_last_name=y.student_last_name FROM
(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 1), ' ', -1) as student_first_name,
SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 2), ' ', -1) as student_middle_name,
SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 3), ' ', -1) as student_last_name
FROM ms_student) y
我的内部查询工作正常。但在更新中有问题
答案 0 :(得分:0)
为什么需要使用简单更新命令
的子查询update ms_student
set
student_first_name= SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 1), ' ', -1),
student_middle_name = SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 2), ' ', -1),
student_last_name = SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 3), ' ', -1) ;
答案 1 :(得分:0)
你在update子句中有多个表
Update ms_student x,(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 1), ' ', -1) as student_first_name,
SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 2), ' ', -1) as student_middle_name,
SUBSTRING_INDEX(SUBSTRING_INDEX(student_name, ' ', 3), ' ', -1) as student_last_name
FROM ms_student) y
set x.student_first_name=y.student_first_name,x.student_middle_name=y.student_middle_name,x.student_last_name=y.student_last_name;