题解 | #将id=5以及emp_no=10001的行数据替换成id=5以及emp_no=10005#
将id=5以及emp_no=10001的行数据替换成id=5以及emp_no=10005
http://www.nowcoder.com/practice/2bec4d94f525458ca3d0ebf3bc8cd240
三种解题方法
直接替换
update titles_test
set emp_no = replace(emp_no, 10001, 10005)
where id=5;
遇上重复key
INSERT INTO titles_test
VALUES(5, 10001 ,'Senior Engineer', '1986-06-26', '9999-01-01')
ON DUPLICATE KEY UPDATE emp_no = 10005;
set emp_no = replace(emp_no, 10001, 10005)
where id=5;
遇上重复key
INSERT INTO titles_test
VALUES(5, 10001 ,'Senior Engineer', '1986-06-26', '9999-01-01')
ON DUPLICATE KEY UPDATE emp_no = 10005;
遇上primary key或unique key时
REPLACE INTO titles_test
VALUES(5, 10005 ,'Senior Engineer', '1986-06-26', '9999-01-01') ;
REPLACE INTO titles_test
VALUES(5, 10005 ,'Senior Engineer', '1986-06-26', '9999-01-01') ;