未进行100%测试,但这可能有效:
SELECT a.post_title, m1.meta_value AS SKU, m2.meta_value AS PRICE
FROM wp_posts a
LEFT JOIN wp_postmeta m1
ON a.ID = m1.post_id
LEFT JOIN wp_postmeta m2
ON a.ID = m2.post_id
WHERE a.post_type=\'product\'
AND m1.meta_key=\'_sku\'
AND m2.meta_key=\'_price\'
请注意
_price
字段对应于“销售价格”(如果存在),因此您还可以获取“标价”:
SELECT a.post_title, m1.meta_value AS SKU, m2.meta_value AS SALE_PRICE, m3.meta_value AS LIST_PRICE
FROM wp_posts a
LEFT JOIN wp_postmeta m1
ON a.ID = m1.post_id
LEFT JOIN wp_postmeta m2
ON a.ID = m2.post_id
LEFT JOIN wp_postmeta m3
ON a.ID = m3.post_id
WHERE a.post_type=\'product\'
AND m1.meta_key=\'_sku\'
AND m2.meta_key=\'_price\'
AND m3.meta_key=\'_regular_price\'
<小时>