我正在使用woocommerce和一個可以節省產品成本的插件。我試圖找出哪些產品沒有註冊此信息。如何在兩個表中找到匹配的行,不存在於第二個
所以我有兩個SQL,現在正常工作,一個返回所有產品,另一個只返回具有成本信息的產品。
我試圖做一個減所以得到沒有成本信息的產品列表。問題是查詢不起作用。我嘗試了不同的東西:
SELECT WP.post_title
FROM wp_posts as WP, wp_postmeta as PM
WHERE PM.meta_key='_posr_cost_of_good'
and PM.post_id=WP.ID
and WP.post_status='publish'
and WP.post_type='product' NOT in (
SELECT WP.post_title
FROM wp_posts as WP
where WP.post_status='publish'
and WP.post_type='product')
上面的函數返回零結果。
使用減去一個查詢提供了一個錯誤:
SELECT WP.post_title
FROM wp_posts as WP
where WP.post_status='publish'
and WP.post_type='product'
MINUS
SELECT WP.post_title
FROM wp_posts as WP, wp_postmeta as PM
WHERE PM.meta_key='_posr_cost_of_good'
and PM.post_id=WP.ID
and WP.post_status='publish'
and WP.post_type='product'
的錯誤是:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MINUS (SELECT WP.post_title FROM wp_posts as WP, wp_postmeta as PM WHERE P' at line 4"
的負查詢做工精細兩個部分。第一個結果爲482個結果,第二個結果爲330個結果。
感謝您的提示,設法讓它與以下工作: SELECT WP.post_title,CONCAT('https://www.tudosaudavel.com/wp-admin/post.php?post=',WP .ID, '和行動=編輯') FROM wp_posts爲WP LEFT JOIN wp_postmeta爲下午PM.post_id = WP.ID AND PM.meta_key = '_ posr_cost_of_good' WHERE WP.post_status = '發佈' 和WP.post_type ='product' AND PM.post_id IS NULL – user3905599