如何从mysql中的单个列更新单个数据

时间:2014-08-25 13:24:38

标签: mysql sql-update

我正在使用复选框插入汽车。我想从列表中删除奥迪汽车。我怎样才能实现这一目标

+----+------------+-----------------+----------+---------+------------+----------+
| id | sms        | Cars            | usertype | noprice | regdate    | time     |
+----+------------+----------+----------+---------+------------+----------+------
| 82 | hello boys | BMW Audi Maruti |  Driver  | 50      | 2014-08-24 | 09:11:50 |
+----+------------+-----------------+----------+---------+------------+----------+

预期结果

+----+------------+------------+----------+---------+------------+----------+
| id | sms        |   Cars     | usertype | noprice | regdate    | time     |
+----+------------+----------+----------+---------+------------+----------+--
| 82 | hello boys | BMW Maruti | Driver    | 50      | 2014-08-24 | 09:11:50|
+----+------------+------------+----------+---------+------------+----------+

1 个答案:

答案 0 :(得分:1)

您可以使用replace()功能更新专栏

update table set cars = replace(cars ,'Audi','') where id = 82

Demo

或者更好地将汽车与单个用户关联在一个单独的表中,其中包含汽车名称和相关的用户ID,每个汽车和用户关系在一个单独的行中