$query = mysql_query("UPDATE a SET fruit = '**apple**' WHERE id = '**1**' "); $query2 = mysql_query("UPDATE a SET fruit = '**orange**' WHERE id = '**2**' "); $query3 = mysql_query("UPDATE a SET fruit = '**peach**' WHERE id = '**3**' ");
有什么方法可以简化为一个查询吗?
是的,您可以使用以下查询进行操作:
UPDATE a SET fruit = (CASE id WHEN 1 THEN 'apple' WHEN 2 THEN 'orange' WHEN 3 THEN 'peach' END) WHERE id IN(1,2 ,3);