开发者

mysql_query minus 1 everything

开发者 https://www.devze.com 2023-02-06 21:58 出处:网络
I have a table, 3 columns, ID (prmiary, auto-inc),counter (UNSIGNED INT), text (VARCHAR) There are 1 million rows.

I have a table, 3 columns,

ID (prmiary, auto-inc),counter (UNSIGNED INT), text (VARCHAR)

There are 1 million rows.

I would like to go through the table and minus 1 from the counter value for each row (开发者_高级运维also, what happens if it is 0 and -1 happens [i set it as unsigned when I made the table? can a query handle this?).

What is the best mysql_query to do this using php?


UPDATE table SET counter = counter - 1
WHERE counter > 0

It should just not update when counter - 1 < 0, iirc.


I would use UPDATE LOW_PRIORITY table SET counter = counter - 1 WHERE counter > 0;

0

精彩评论

暂无评论...
验证码 换一张
取 消