2

我现在正在查询 2 天,但我不知道如何进行。

基本上我正在使用多个连接进行查询:

我的查询:

SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_content, wp_posts.post_type,     
wp_term_taxonomy.taxonomy, wp_terms.name
FROM wp_term_relationships, wp_term_taxonomy, wp_terms, wp_posts
WHERE wp_term_relationships.object_id =80
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id
AND wp_term_relationships.object_id = wp_posts.ID

这就是她展示的(在顶部),以及我想要展示的(底部)

http://tinyurl.com/cnjmuxs

非常感谢您的帮助

4

1 回答 1

2

也许其他人有更清洁的方法来做到这一点,但以下应该有效:

SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_content, wp_posts.post_type, 
    MAX(
        CASE WHEN wp_term_taxonomy.taxonomy = 'reference' THEN wp_terms.name ELSE '' END 
    ) AS reference,
    MAX(
        CASE WHEN wp_term_taxonomy.taxonomy = 'chinesename' THEN wp_terms.name ELSE '' END 
    ) AS chinesename,
    MAX(
        CASE WHEN wp_term_taxonomy.taxonomy = 'price' THEN wp_terms.name ELSE '' END 
    ) AS price
FROM wp_term_relationships, wp_term_taxonomy, wp_terms, wp_posts
WHERE wp_term_relationships.object_id =80
    AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
    AND wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id
    AND wp_term_relationships.object_id = wp_posts.ID
GROUP BY wp_posts.ID, wp_posts.post_title, wp_posts.post_content, wp_posts.post_type
于 2012-05-06T01:23:25.737 回答