简体   繁体   中英

mysql_query minus 1 everything

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.

我将使用UPDATE LOW_PRIORITY table SET counter = counter - 1 WHERE counter > 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM