篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MySQL Query以获取具有属性的所有产品相关的知识,希望对你有一定的参考价值。
SELECT p.`ID` AS 'Product ID',
p.`post_title` AS 'Product Name',
t.`term_id` AS 'Attribute Value ID',
REPLACE(REPLACE(tt.`taxonomy`, 'pa_', ''), '-', ' ') AS 'Attribute Name',
t.`name` AS 'Attribute Value'
FROM `wp_posts` AS p
INNER JOIN `wp_term_relationships` AS tr ON p.`ID` = tr.`object_id`
INNER JOIN `wp_term_taxonomy` AS tt ON tr.`term_taxonomy_id` = tt.`term_id`
AND tt.`taxonomy` LIKE 'pa_%'
INNER JOIN `wp_terms` AS t ON tr.`term_taxonomy_id` = t.`term_id`
WHERE p.`post_type` = 'product'
AND p.`post_status` = 'publish'
ORDER BY p.`ID`
以上是关于sql MySQL Query以获取具有属性的所有产品的主要内容,如果未能解决你的问题,请参考以下文章