如果该行的现有值与UPDATE语句中的WHERE子句匹配,则可以使用该行的现有值来提供新值。以下是演示它的示例。
假设我们有一个名为“ tender”的表,如下所示:
mysql> Select * from tender; +-----------+---------+------+ | tender_id | company | rate | +-----------+---------+------+ | 200 | ABC | 1000 | | 300 | ABD | 6000 | | 301 | ABE | 7000 | | 302 | ABF | 3500 | | 303 | ABG | 3600 | +-----------+---------+------+ 5 rows in set (0.00 sec)
以下查询将把bid_id列中的值增加100,并根据新的“ tender_id”更新“ rate”列。
mysql> UPDATE tender SET tender_id = tender_id + 100, rate = tender_id + 500 Where tender_id > 300; Rows matched: 3 Changed: 3 Warnings: 0 mysql> Select * from tender; +-----------+----------+------+ | tender_id | company | rate | +-----------+----------+------+ | 200 | ABC | 1000 | | 300 | ABD | 5000 | | 401 | ABE | 901 | | 402 | ABF | 902 | | 403 | ABG | 903 | +-----------+----------+------+ 5 rows in set (0.00 sec)