列表

详情


SQL110. 插入记录(一)

描述

牛客后台会记录每个用户的试卷作答记录到exam_record表,现在有两个用户的作答记录详情如下:

试卷作答记录表exam_record中,表已建好,其结构如下,请用一条语句将这两条记录插入表中。

Filed Type Null Key Extra Default Comment
id int(11) NO PRI auto_increment (NULL) 自增ID
uid int(11)
NO


(NULL)
用户ID
exam_id int(11)
NO


(NULL)
试卷ID
start_time datetime NO


(NULL)
开始时间
submit_time datetime
YES

(NULL)
提交时间
score tinyint(4)
YES


(NULL)
得分
该题最后会通过执行SELECT uid, exam_id, start_time, submit_time, score FROM exam_record;来对比结果

示例1

输入:

drop table if EXISTS exam_record;
CREATE TABLE IF NOT EXISTS exam_record (
id int PRIMARY KEY AUTO_INCREMENT COMMENT '自增ID',
uid int NOT NULL COMMENT '用户ID',
exam_id int NOT NULL COMMENT '试卷ID',
start_time datetime NOT NULL COMMENT '开始时间',
submit_time datetime COMMENT '提交时间',
score tinyint COMMENT '得分'
)CHARACTER SET utf8 COLLATE utf8_general_ci;
TRUNCATE exam_record;

输出:

1001|9001|2021-09-01 22:11:12|2021-09-01 23:01:12|90
1002|9002|2021-09-04 07:01:02|None|None

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Mysql 解法, 执行用时: 35ms, 内存消耗: 6304KB, 提交时间: 2022-01-25

insert INTO exam_record values(null,1001,9001,'2021-09-01 22:11:12','2021-09-01 23:01:12',90),
(null,1002,9002,'2021-09-04 07:01:02',null,null);

Mysql 解法, 执行用时: 35ms, 内存消耗: 6352KB, 提交时间: 2021-11-30

insert into exam_record (id,uid,exam_id,start_time,submit_time,score)
VALUES(null,1001,9001,'2021-09-01 22:11:12','2021-09-01 23:01:12',90),
(null,1002,9002,'2021-09-04 7:01:02',null,null)

Mysql 解法, 执行用时: 35ms, 内存消耗: 6468KB, 提交时间: 2022-01-23

insert into exam_record
(uid, exam_id, start_time, submit_time, score)
values
(1001,9001,'2021-09-01 22:11:12',
 '2021-09-01 22:11:12'+interval 50 minute,90),
(1002,9002,'2021-09-04 07:1:2', null,null);

Mysql 解法, 执行用时: 36ms, 内存消耗: 6184KB, 提交时间: 2022-01-25

insert into exam_record values
(null,1001,9001,"2021-09-01 22:11:12","2021-09-01 23:01:12",90),
(null,1002,9002,"2021-09-04 07:01:02",null,null)

Mysql 解法, 执行用时: 36ms, 内存消耗: 6184KB, 提交时间: 2021-12-07

insert into exam_record(uid, exam_id, start_time, submit_time, score)
values
    (1001, 9001, "2021-09-01 22:11:12", "2021-09-01 23:01:12", 90),
    (1002, 9002, "2021-09-04 07:01:02", null, null);

上一题