如何将C#数据序列化为wp_postmeta(MySQL longtext专栏)

时间:2014-03-05 10:37:25

标签: mysql replace

我正在尝试编写一个SQL更新,它接受一部分字符串并使用另一个字符串的一部分进行更新(两个字符串已经在数据库中)。

我的查询看起来像这样,但它不起作用:(

UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 
      SELECT SUBSTRING(meta_value, 1, 23) AS meta_header 
             FROM wp_postmeta WHERE meta_id = 8443, 
      SELECT SUBSTRING(meta_value, 1, 23) AS meta_header 
             FROM wp_postmeta WHERE meta_id = 2037)
WHERE post_id = 8443

关于如何写它的任何想法?

感谢。

2 个答案:

答案 0 :(得分:0)

这有用吗?

replace into wp_postmeta (meta_id,meta_value) 
select 8443,concat(SUBSTRING(meta_value,1,23),t.end) 
from wp_postmeta JOIN 
(select SUBSTRING(meta_value,24) as end from wp_postmeta where meta_id=8443) as t
where meta_id=2037

使用group_concat解决方案:

replace into wp_postmeta (meta_id,meta_value) 
select 8443,group_concat(type SEPARATOR '') from 
 (select mem_id,substring(type,1,23) as type from wp_postmeta where mem_id=2037 
 UNION 
 select mem_id,substring(type,24) as type from wp_postmeta where mem_id=8443) as t;

答案 1 :(得分:0)

加入你的表格来试试这个

UPDATE wp_postmeta wp1
JOIN wp_postmeta wp2 ON (wp1.meta_id =wp2.meta_id )
JOIN wp_postmeta wp3 ON (wp1.meta_id =wp3.meta_id )
SET wp1.meta_value = REPLACE(wp1.meta_value, SUBSTRING(wp2.meta_value, 1, 23) ,SUBSTRING(wp3.meta_value, 1, 23))
WHERE wp2.meta_id = 8443 AND wp3.meta_id = 2037
AND wp1.post_id = 8443