0

好的,如果存在另一个值,我正在寻找一个 sql 查询以在特定表中插入 meta_key 和值。我正在使用 wordpress 数据库。

我想要一个查询来在“ wp_postmeta ”表中搜索“ qty (meta_key) ”和“ 0 (meta_value) ”,并在所有这些帖子中插入一个新的 meta_key“ _wplp_post_front ”和 meta_value“ 1

我是 phpmyadmin 的新手,我真的需要帮助。

_ __ _ __ _ __ _ __ _ __ _ __ _ _____更新!!!
好的,我再次从第三方网站找到了解决方案:

INSERT INTO wp_postmeta (meta_key, meta_value, post_id)
SELECT "_wplp_post_front", 1, post_id
 FROM wp_postmeta outside_table
 WHERE meta_key = 'qty'
 AND meta_value = '0'
 AND NOT EXISTS 
(SELECT * FROM wp_postmeta
WHERE post_id = outside_table.post_id
AND meta_key = "_wplp_post_front"
AND meta_value = 1
)
4

1 回答 1

0

好的,我再次从第三方网站找到了解决方案:

INSERT INTO wp_postmeta (meta_key, meta_value, post_id)
SELECT "_wplp_post_front", 1, post_id
 FROM wp_postmeta outside_table
 WHERE meta_key = 'qty'
 AND meta_value = '0'
 AND NOT EXISTS 
(SELECT * FROM wp_postmeta
WHERE post_id = outside_table.post_id
AND meta_key = "_wplp_post_front"
AND meta_value = 1
)
于 2014-03-24T17:58:47.627 回答