我需要从客户端erp数据库中提取wordpress / woocommerce定价。我有一个wordpress(woocommerce)数据库,其中包含在线销售产品的定价。 wordpress MySQL数据库将价格存储在元表中:wp_database.wp_postmeta.meta_key =" _price" wp_database.wp_postmeta.meta_value = 1.99。
我有数千种产品,我需要每天从不同的MySQL数据库更新所有产品:erp_database.part.new_price
唯一ID是:erp_database.part.ID,在wordpress db中,它的wp_database.wp_postmeta.meta_key =" _sku"
这可以在一个查询中完成吗?
这里的wp_database样本数据看起来像(但是1000条记录和几十个密钥):
以下是erp_database的样子:
这已经接近但我认为第一个WHERE子句应该是IN而不是SELECT。有谁知道怎么做?
UPDATE `wp_database`.wm_postmeta AS existing,
erp_database.part AS newpricing
SET existing.pm_postmeta.meta_value =(
SELECT
newpricing.new_price
FROM
newpricing
WHERE
newpricing.ID =(
SELECT
existing.meta_value
WHERE
existing.meta_key = "_sku"
)
)
接近?
UPDATE `wp_database`.wm_postmeta AS existing,
erp_database.part AS newpricing
SET existing.pm_postmeta.meta_value =(
SELECT
newpricing.NEW_PRICE
FROM
newpricing
WHERE
newpricing.ID =(
SELECT
existing.meta_value,
existing.meta_value as newprice
WHERE
existing.meta_key = "_sku" and existing.post_id = newprice.post_id
)
)
答案 0 :(得分:0)
好的,我自己拿到了!!!!对于那些必须从列表,电子表格或外部ERP数据库更新整个woocommerce商店的所有其他人,这里是它的主旨:
UPDATE pm_postmeta as t,
(
SELECT
a.meta_key AS id_key,
a.meta_value AS id_value,
b.meta_key AS price_key,
b.meta_value AS price_value,
a.meta_id,
a.post_id,
erp_database.part.ID,
erp_database.part.price AS "Price"
FROM
`wp_database`.pm_postmeta AS a
INNER JOIN `wp_database`.pm_postmeta AS b ON a.post_id = b.post_id
INNER JOIN erp_database.part ON a.meta_value LIKE concat("%",erp_database.part.ID,"%")
WHERE
a.meta_key = "_sku" AND
b.meta_key = "_price"
ORDER BY
b.post_id ASC
limit 100 ) as thetemp
SET meta_value = thetemp.`Price` WHERE meta_key="_price" and t.post_id = thetemp.post_id
当然众所周知,还有几个地方需要更新价格,并删除缓存......