题解 | #插入记录(二)#
插入记录(二)
http://www.nowcoder.com/practice/9681abf28745468c8adacb3b029a18ce
法一:
INSERT INTO exam_record_before_2021(uid,exam_id,start_time,submit_time,score)
SELECT uid,exam_id,start_time,submit_time,score
FROM exam_record WHERE submit_time<"2021-01-01 00:00:00";
法二:
INSERT INTO exam_record_before_2021
SELECT null,uid,exam_id,start_time,submit_time,score
FROM exam_record WHERE submit_time<"2021-01-01 00:00:00";
复制旧表的时候不需要复制旧表的id,新表自动生成新id。 这里主要mark的是null的用法,这样添加数据可以自增,从而可以添加全部数据,而不用特意规定那几列添加数据。