2016-04-25 61 views
1

我在一個SQL數據庫中有教室時間表。從某個日期插入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'中創建日期後。我想將隨附的地方插入另一個名爲'place'的變量中,在那個特定時間去哪裏。事情是這樣的

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'); 

但我需要確保的條目相匹配,使得在「約會」的第三條中「地方」的第三項匹配。我正在尋找解決方案。如果你有一個更好的全解決方案比這個例子中,請讓我知道:)

+0

你有沒有混合'INSERT'和'UPDATE'命令? – Arvo

回答

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'); 
2
INSERT INTO schedule (place, date) 
VALUES ('Room A','2016-05-16 13:00:00')