我正在使用MySQL ODBC驱动程序来查询产品列表(约830个项目)及其价格,结果以excel表格结尾。到目前为止,仅获取产品列表及其“ _regular_price”和“ _price”一直很好。但是,当我尝试添加元键“ _sale_price”和“ _sale_price_dates_to”时,我会重复获得同一产品的行,并且某些产品同时显示有销售价和无销售价。这是我目前正在使用的SQL:
SELECT wp_postmeta.meta_value, wp_posts.ID, wp_posts.post_title, wp_posts.post_name, wp_postmeta.meta_value AS SKU, wp_postmeta_1.meta_value AS [Reg Price], wp_postmeta_2.meta_value AS Price, wp_postmeta_3.meta_value AS [Sale Price], wp_postmeta_4.meta_value AS [Sale Date To]
FROM wp_postmeta AS wp_postmeta_4 RIGHT JOIN (wp_postmeta AS wp_postmeta_3 RIGHT JOIN (wp_postmeta AS wp_postmeta_2 INNER JOIN (wp_postmeta AS wp_postmeta_1 INNER JOIN (wp_postmeta INNER JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID) ON wp_postmeta_1.post_id = wp_posts.ID) ON wp_postmeta_2.post_id = wp_posts.ID) ON wp_postmeta_3.post_id = wp_posts.ID) ON wp_postmeta_4.post_id = wp_posts.ID
WHERE (((wp_postmeta.meta_value)<>"1156") AND ((wp_posts.post_type)="PRODUCT") AND ((wp_postmeta.meta_key)="_sku") AND ((wp_postmeta_1.meta_key)="_regular_price") AND ((wp_postmeta_2.meta_key)="_price") AND ((wp_postmeta_3.meta_key)="_sale_price") AND ((wp_postmeta_4.meta_key)="_sale_price_dates_to"));
我已经检查了上述查询在wordpress的admin区域中返回的某些产品,尽管其中一些确实在产品记录的“常规”区域显示了销售价格,但其他产品却没有销售价格-但查询返回该产品的价格。我对woocommerce不太熟悉,对此我有点茫然。