0

这些是 table column 上的情况post_attendingpost_attending可能是:5or 5,6,7or 6,7,5or or 6,5,7or ''or more string comma separator and 5 on this or not。我应该如何删除,在 PDO 查询中使用的“5”和“可能”?

我试过这个:

$q= "UPDATE table SET post_attending = SUBSTR(REPLACE(CONCAT(',', post_attending, ','), ? , ','), 2, LENGTH(REPLACE(CONCAT(',', post_attending, ','), ? , ',')) - 2) WHERE id = x "
$sql->execute(array(5,5,x)); 

,但是当最后有一个 5 或 5 时,它给我留下了一个。

我读过这个也TRIM(BOTH ',' FROM REPLACE(wishes, '(,)? :var (,)?', ''))没有真正弄清楚正确的语法。

4

2 回答 2

0

不使用任何CASE语句,我相信它会更快

UPDATE table SET post_attending = SELECT REPLACE(REPLACE(REPLACE(REPLACE(val, ',5,', ','), ',5', ''), '5,', ''),'5', '')
于 2013-02-27T16:45:20.103 回答
0

尝试这个:

update table
    set post_attending = (case when val like '5,%' then SUBSTRING(val, 3, LENgth(val) - 2)
                               when val like '%,5' then SUBSTRING(val, 1, length(val) - 2)
                               when val = '5' then ''
                               else REPLACE(val, ',5,', ',')
                           end)
于 2013-02-27T16:23:20.957 回答