1. Summary of ways to modify records:
- Set to new value: UPDATE table_name SET column_name=new_value [, column_name2=new_value2] [WHERE column_name3=value3]
- Replace according to the existing value: UPDATE table_name SET key1=replace(key1, 'Find content', 'Replace with content') [WHERE column_name3=value3]
2. Case
(1) There is an examination paper information table examination_info, the table structure is shown in the following figure:
Filed | Type | Null | Key | Extra | Default | Comment |
id | int(11) | NO | AT | auto_increment | (NULL) | auto-increment ID |
exam_id | int(11) | NO | UNI | (NULL) | paper ID | |
tag | char(32) | YES | (NULL) | category label | ||
difficulty | char(8) | YES | (NULL) | difficulty | ||
duration | int(11) | NO | (NULL) | duration | ||
release_time | datetime | YES | (NULL) | release time |
--t1:
update examination_info
set tag = replace(tag,'PYTHON','Python')
where tag = 'PYTHON';
--t2:
update examination_info
set tag = 'Python'
where tag = 'PYTHON';
Please change all the tag fields tagged PYTHON in the examination_info table to Python.
(2) There is an examination paper answer record table exam_record, which contains user answer paper records for many years, and the structure is as follows:
Answer record table exam_record:
submit_time is the completion time
Filed | Type | Null | Key | Extra | Default | Comment |
id | int(11) | NO | AT | auto_increment | (NULL) | auto-increment ID |
uid | int(11) | NO | (NULL) | User ID | ||
exam_id | int(11) | NO | (NULL) | paper ID | ||
start_time | datetime | NO | (NULL) | Starting time | ||
submit_time | datetime | YES | (NULL) | submission time | ||
score | tinyint(4) | YES | (NULL) | Score |
update exam_record
set score = 0,submit_time = '2099-01-01 00:00:00'
where start_time < '2021-09-01 00:00:00' and score is null;
Please change all unfinished records in the exam_record table that started answering before September 1, 2021 to passive completion, that is, change the completion time to '2099-01-01 00:00:00' and the score to 0.