@(一隻心中無碼的程序員)專欄程序員
- ~
題目描述
將全部to_date爲9999-01-01的所有更新爲NULL,且 from_date更新爲2001-01-01。
CREATE TABLE IF NOT EXISTS titles_test (
id int(11) not null primary key,
emp_no int(11) NOT NULL,
title varchar(50) NOT NULL,
from_date date NOT NULL,
to_date date DEFAULT NULL);sql
insert into titles_test values ('1', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('2', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('3', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('4', '10004', 'Senior Engineer', '1995-12-03', '9999-01-01'),
('5', '10001', 'Senior Engineer', '1986-06-26', '9999-01-01'),
('6', '10002', 'Staff', '1996-08-03', '9999-01-01'),
('7', '10003', 'Senior Engineer', '1995-12-03', '9999-01-01');code
用 UPDATE 語句更新若干列的最基本用法,詳細可參考: http://www.w3school.com.cn/sql/sql_update.asp https://www.w3schools.com/sql/sql_update.asp 另外要注意若干列 to_date = NULL 和 from_date = '2001-01-01' 之間只能用逗號鏈接,切勿用 AND 鏈接。 UPDATE titles_test SET to_date = NULL, from_date = '2001-01-01' WHERE to_date = '9999-01-01';