2015-02-23 18 views
0

我要追加號碼與我的表列文本更新列追加與列文本的數字

Post_sortcode

post-first 
post-next 
post-next 

輸出

Post_sortcode

post-first-1 
post-next-2 
post-next-3 

任何一個可以幫助我...

+0

你在表中有主鍵嗎? – 2015-02-23 11:39:28

+0

ya post_id是我的主鍵 – 2015-02-23 11:40:15

回答

1

您需要使用動態變量來獲取行號,然後與加入的東西作爲

update Post_sortcode t join 
(
    select 
    t1.post_id, 
    @r := @r+1 as rr 
    from Post_sortcode t1,(select @r:=0)r 

)u on u.post_id = t.post_id 
set t.post = concat(t.post,'-',u.rr); 

DEMO

1

你可以試試這個 -

更新
update tbl_post set post_sortcode=concat(post_sortcode,'-',post_id) 
+0

在mysql中試試這個,看看你得到了什麼'select'title-here - '+ 1;' – 2015-02-23 11:47:59