0

嘿伙计们,我想知道每个查询一次可以使用超过 1 个 INSERT 吗?还是每次插入都必须一次完成?

例如,我想将这两个查询作为一个查询来执行以节省服务器资源:

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES ('2012-09-01', '5', '4', '3', '2') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '4', endEmails = '3', emailsAnswered = '2'
INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES ('2012-09-2', '5', '6', '7', '8') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '6', endEmails = '7', emailsAnswered = '8'

有没有将它们结合起来?我试着把它们放在同一个查询中,但它不喜欢它。

4

3 回答 3

1

是的,你可以试试这个

INSERT INTO tbl_name(col1,col2,col3) VALUES ('aaa','bbb','ccc'),('ddd','eee','fff');

或者您可以在第一个查询之后放置分号并继续第二个查询。

希望这可以帮助。

于 2012-10-10T10:05:13.133 回答
1
INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) 
VALUES ('2012-09-01', '5', '4', '3', '2') 
ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '4', endEmails = '3', emailsAnswered = '2';

('2012-09-2', '5', '6', '7', '8') 
ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = '6', endEmails = '7', emailsAnswered = '8'
于 2012-10-10T10:08:00.027 回答
0

用分号“;”分隔 喜欢 :

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) 
VALUES ('2012-09-01', '5', '4', '3', '2') ON DUPLICATE KEY UPDATE supportStaff = '5', 
startEmails = '4', endEmails = '3', emailsAnswered = '2';

INSERT INTO ExtraStats (date, supportStaff, startEmails, endEmails, emailsAnswered) VALUES 
('2012-09-2', '5', '6', '7', '8') ON DUPLICATE KEY UPDATE supportStaff = '5', startEmails = 
'6', endEmails = '7', emailsAnswered = '8';
于 2012-10-10T10:01:03.057 回答