我有一张有很多行的表(大约 1,500 行)。在 city_name 列中,一些单元格具有城市名称并以 (CD) 结尾。我希望那些带有 (CD) 的单元格在没有 (CD) 的情况下更新。这是我的表的预览:
+---------+-----------------------+---------+
| city_id | city_name | id_dept |
+---------+-----------------------+---------+
| 1 | El Encanto (CD) | 1 |
| 2 | La Chorrera (CD) | 1 |
| 3 | La Pedrera (CD) | 1 |
| 4 | La Victoria (CD) | 1 |
| 5 | Leticia | 1 |
| 6 | Miriti Parana (CD) | 1 |
| 7 | Puerto Alegria (CD) | 1 |
| 8 | Puerto Arica (CD) | 1 |
| 9 | Puerto Nariño | 1 |
| 10 | Puerto Santander (CD) | 1 |
+---------+-----------------------+---------+
10 rows in set (0.00 sec)
这就是我想要的:
+---------+-----------------------+---------+
| city_id | city_name | id_dept |
+---------+-----------------------+---------+
| 1 | El Encanto | 1 |
| 2 | La Chorrera | 1 |
| 3 | La Pedrera | 1 |
| 4 | La Victoria | 1 |
| 5 | Leticia | 1 |
| 6 | Miriti Parana | 1 |
| 7 | Puerto Alegria | 1 |
| 8 | Puerto Arica | 1 |
| 9 | Puerto Nariño | 1 |
| 10 | Puerto Santander | 1 |
+---------+-----------------------+---------+
10 rows in set (0.00 sec)
好吧,我知道我可以使用 (CD) 选择所有行:
SELECT * FROM city WHERE city_name LIKE ( "%(CD)%" )
但是如何删除(CD):
UPDATE city SET city_name = "" WHERE city_name LIKE( "%(CD)%" )