1

我正在维护一个至少有 100 行的数据库。每 10 秒进行一次 ajax 调用以更新行。我觉得每 10 秒调用 100 次更新查询是不可取的。所以我遇到了mysql案例,然后和何时将100个查询组合到一个查询并进行更新。但我遇到了代码问题。这是我的两行代码

update customer_details set (date,customer_name,school_name,mobile_number,customer_email,age,area,customer_requirement,extra_comments,draft_message) = 
 case `id`
when '275' then ('09-04-201','person1','','1234567890','','','','basketball','','message')
when '274' then  ( '','','','','','','area','xyz','','message')
end

错误是

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(date,customer_name,school_name,mobile_number,customer_email,age,area,customer_r' at line 1

我无法纠正错误。还有其他方法可以对 100 行进行单个查询调用吗?

4

2 回答 2

1

您需要在 set 语句中设置每一列,语法为:

UPDATE tablename SET column1 = "value1", column2 = "value2" ....
WHERE IdDColumn = MyID

在您的情况下,您将有两种选择:

UPDATE tablename SET Column1 =  
CASE
  WHEN id = 275 THEN Value1
  WHEN id = 274 THEN Value2
  ELSE DefaultValue 
END, Column2 =  
CASE
  WHEN id = 275 THEN Value1
  WHEN id = 274 THEN Value2
  ELSE DefaultValue  
END,
etc...
于 2013-04-17T05:52:39.620 回答
1

你试过:

INSERT INTO customer_details (id, date,customer_name,school_name,mobile_number,customer_email,age,area,customer_requirement,extra_comments,draft_message) VALUES
(275, '09-04-201','person1','','1234567890','','','','basketball','','message'),
(274, '','','','','','','area','xyz','','message')
ON DUPLICATE KEY UPDATE 
date=VALUES(date),
customer_name=VALUES(customer_name),
school_name=VALUES(school_name),
mobile_number=VALUES(mobile_number),
customer_email=VALUES(customer_email),
age=VALUES(age),
area=VALUES(area),
customer_requirement=VALUES(customer_requirement),
extra_comments=VALUES(extra_comments),
draft_message=VALUES(draft_message);
于 2013-04-17T05:54:17.177 回答