SQL更新具有相同值的多个行

时间:2022-10-19 20:37:16

I use this to update (add points) rows which mgroup is 15

我用它来更新(添加点)mgroup为15的行

UPDATE ibf_members SET points = points + 500 WHERE mgroup = 15

What can I use to update (add points + 500) for rows which has its id as 5, 7, 10, 11, 16, 25 and also has mgroup as 15?

对于id为5,7,10,11,16,25并且mgroup为15的行,我可以使用什么来更新(添加点+500)?

2 个解决方案

#1


16  

You can use the IN clause for this, which is easier to read (and possibly more efficient?) than building a giant OR list. Try something like:

您可以使用IN子句,这比构建一个巨大的OR列表更容易阅读(并且可能更高效?)。尝试以下方法:

UPDATE ibf_members
SET points = points + 500
WHERE mgroup = 15
AND id IN (5, 7, 10, 11, 16, 25);

#2


1  

Just add another condition to your WHERE clause:

只需在WHERE子句中添加另一个条件:

UPDATE ibf_members SET points = points + 500 WHERE mgroup = 15 AND id IN (5, 7, 10, 11, 16, 25)

#1


16  

You can use the IN clause for this, which is easier to read (and possibly more efficient?) than building a giant OR list. Try something like:

您可以使用IN子句,这比构建一个巨大的OR列表更容易阅读(并且可能更高效?)。尝试以下方法:

UPDATE ibf_members
SET points = points + 500
WHERE mgroup = 15
AND id IN (5, 7, 10, 11, 16, 25);

#2


1  

Just add another condition to your WHERE clause:

只需在WHERE子句中添加另一个条件:

UPDATE ibf_members SET points = points + 500 WHERE mgroup = 15 AND id IN (5, 7, 10, 11, 16, 25)