[英]WordPress: Subquery with table join
查詢按瀏覽量對帖子進行排序-效果很好。 但是我也需要加入wp_term_taxonomy.term_taxonomy_id 。 像這樣:
WHERE wp_term_taxonomy.term_taxonomy_id ='2'
編碼:
$qstr = "
SELECT wposts.*
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
group by postid) pv
WHERE wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND wposts.ID = pv.postid
ORDER BY pv.pageviews DESC
LIMIT 10
";
我嘗試了這個:
$qstr = "
SELECT wposts.*, wp_term_taxonomy.term_taxonomy_id
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
group by postid) pv
WHERE wposts.post_status = 'publish'
INNER JOIN
wp_term_taxonomy
AND xxxx // dont know
WHERE wp_term_taxonomy.term_taxonomy_id = '13'
AND wposts.post_type = 'post'
AND wposts.ID = pv.postid
ORDER BY pv.pageviews DESC
LIMIT 10
";
你為什么要使用join? 這項工作對您沒有幫助:
$qstr = "
SELECT wposts.*, wp_term_taxonomy.term_taxonomy_id
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
group by postid) pv, wp_term_taxonomy
WHERE wposts.post_status = 'publish'
AND wp_term_taxonomy.term_taxonomy_id = '13'
AND wposts.post_type = 'post'
AND wposts.ID = pv.postid
ORDER BY pv.pageviews DESC
LIMIT 10 ";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.