4
SELECT b.post_title, a.post_id, COUNT( * ) as Total
FROM  wp_posts b INNER JOIN 
            wp_postmeta a ON a.post_id = b.ID
    WHERE a.meta_value = 1
      AND a.meta_key = 'type-select' 
      AND b.post_status = 'publish'
      and post_type = 'car-cc'
GROUP BY b.post_title, a.post_id

現在、それは選択さpost titleれていますが、どこのメタキー= type-genpost idも選択する必要があります。問題は、別のメタキーがクエリで既に比較されていることです。meta value

SQL フィドル: http://sqlfiddle.com/#!2/109c2/1

4

3 に答える 3

3

どうぞ

SELECT b.post_title, a.post_id, COUNT( * ) AS Total,
(SELECT meta_value FROM  `wp_postmeta` WHERE post_id= b.ID AND meta_key='type-gen') AS 'new  meta value'
FROM  wp_posts b INNER JOIN 
            wp_postmeta a ON a.post_id = b.ID
    WHERE a.meta_value = 1
      AND a.meta_key = 'type-select' 
      AND b.post_status = 'publish'
      AND post_type = 'car-cc'
GROUP BY b.post_title, a.post_id

フィドル

于 2013-07-24T14:00:54.947 に答える
1
SELECT b.post_title, a.post_id, COUNT( * ) as Total
FROM  wp_posts b INNER JOIN 
            wp_postmeta a ON a.post_id = b.ID
    WHERE (a.meta_value = 1
      AND a.meta_key = 'type-select' 
      AND b.post_status = 'publish'
      and post_type = 'car-cc') 
    OR (a.meta_value = 1
      AND a.meta_key = 'type-gen' 
      AND b.post_status = 'publish'
      and post_type = 'car-cc')
GROUP BY b.post_title, a.post_id
于 2013-07-24T13:32:59.687 に答える