我在SQL数据库中有课堂时间表。
INSERT INTO schedule (date)
VALUES
('2016-05-16 13:00:00'),
('2016-05-16 14:00:00'),
('2016-05-16 15:00:00'),
('2016-05-16 16:00:00'),
('2016-05-16 17:00:00'),
('2016-05-17 13:00:00'),
('2016-05-17 14:00:00'),
('2016-05-17 15:00:00'),
('2016-05-17 16:00:00'),
('2016-05-17 17:00:00'),
('2016-05-18 13:00:00'),
('2016-05-18 14:00:00'),
('2016-05-18 15:00:00'),
('2016-05-18 16:00:00'),
('2016-05-18 17:00:00'),
('2016-05-19 13:00:00'),
('2016-05-19 14:00:00'),
('2016-05-19 15:00:00'),
('2016-05-19 16:00:00'),
('2016-05-19 17:00:00');
我在变量' date'中创建了日期。我想将附带的地方插入另一个名为“地点”的变量中。在那个特定的时间去哪里。像这样的东西
INSERT INTO schedule (place)
VALUES
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A'),
('Room A');
但是我需要确保条目匹配,以便第三个条目在' date'匹配' place'中的第三个条目。我正在寻找解决方案。如果你的解决方案比这个例子更好,请告诉我:)
答案 0 :(得分:2)
INSERT INTO schedule (place, date)
VALUES ('Room A','2016-05-16 13:00:00')
答案 1 :(得分:1)
首先insert
之后,您必须使用update
语句。像这样:
update schedule
set place='Room A'
或者您可以像insert
一样执行此操作:
INSERT INTO schedule (date, place)
VALUES
('2016-05-16 13:00:00','Room A'),
('2016-05-16 14:00:00','Room A'),
('2016-05-16 15:00:00','Room A'),
('2016-05-16 16:00:00','Room A'),
('2016-05-16 17:00:00','Room A'),
('2016-05-17 13:00:00','Room A'),
('2016-05-17 14:00:00','Room A'),
('2016-05-17 15:00:00','Room A'),
('2016-05-17 16:00:00','Room A'),
('2016-05-17 17:00:00','Room A'),
('2016-05-18 13:00:00','Room A'),
('2016-05-18 14:00:00','Room A'),
('2016-05-18 15:00:00','Room A'),
('2016-05-18 16:00:00','Room A'),
('2016-05-18 17:00:00','Room A'),
('2016-05-19 13:00:00','Room A'),
('2016-05-19 14:00:00','Room A'),
('2016-05-19 15:00:00','Room A'),
('2016-05-19 16:00:00','Room A'),
('2016-05-19 17:00:00','Room A');