SQL:使用替换空间从列复制到另一列

时间:2014-11-16 16:56:20

标签: php mysql

我的DataBase就像这样: -

ID       Name              Url         Date
11   News title test2               22-10-2014
12   News title test3               22-10-2014
13   News title test4               22-10-2014

现在我需要将值从Name复制到Url并将空格替换为-

所以,表格必须像复制后一样: -

ID       Name                     Url                    Date
11   News title test2       News-title-test2           22-10-2014
12   News title test3       News-title-test2           22-10-2014
13   News title test4       News-title-test2           22-10-2014

是否可以通过SQLPHP

执行此操作

1 个答案:

答案 0 :(得分:3)

只需更新表格并使用REPLACE()功能

即可
UPDATE table
SET Url = REPLACE(Name,' ', '-')