我正在尝试获取过去30天的综合浏览量。和浏览量总计。但出于某种原因,我得到了两者相同的价值。因此,它将价值观合并在一起。
SELECT p.ID,
p.post_title post_title,
p.post_date post_date,
SUM(gvd.unique_pageviews) total_unique_pageviews,
SUM(gvd.pageviews) total_pageviews,
thirty_days_views.unique_pageviews thirty_days_views_unique_pageviews,
thirty_days_views.pageviews thirty_days_views_pageviews
FROM wp_posts as p
INNER JOIN wp_postmeta as pm on pm.post_id = p.ID
LEFT JOIN wp_google_views_daily gvd ON gvd.post_id = p.ID
LEFT JOIN (
SELECT p.ID,
SUM(gvd.unique_pageviews) unique_pageviews,
SUM(gvd.pageviews) pageviews
FROM wp_posts p
INNER JOIN wp_postmeta as pm on pm.post_id = p.ID
LEFT JOIN wp_google_views_daily gvd ON gvd.post_id = p.ID
WHERE
pm.meta_key = 'template_style'
AND pm.meta_value = 'list'
AND p.post_status = 'publish'
AND p.post_password = ''
AND p.post_date >= DATE(DATE_SUB(NOW(), INTERVAL 30 day))
GROUP BY p.ID
ORDER BY p.post_date DESC
) thirty_days_views ON thirty_days_views.ID = p.ID
WHERE
pm.meta_key = 'template_style'
AND pm.meta_value = 'list'
AND p.post_status = 'publish'
AND p.post_password = ''
GROUP BY
p.ID
ORDER BY
p.post_date DESC
如何获取不受其他子查询影响的值?这样我可以获得过去30天的总浏览量和综合浏览量?
答案 0 :(得分:0)
我工作的人帮助了我。这是解决方案:
SELECT
p.ID,
p.post_title post_title,
p.post_date post_date,
all_days_views.unique_pageviews total_unique_pageviews,
all_days_views.pageviews total_pageviews,
thirty_days_views.unique_pageviews thirty_days_views_unique_pageviews,
thirty_days_views.pageviews thirty_days_views_pageviews
FROM
wp_posts as p
INNER JOIN wp_postmeta as pm on pm.post_id = p.ID and pm.meta_key = 'template_style' and pm.meta_value = 'list'
LEFT JOIN (
SELECT
post_id,
SUM(unique_pageviews) unique_pageviews,
SUM(pageviews) pageviews
FROM
wp_google_views_daily
GROUP BY post_id
) all_days_views ON all_days_views.post_id = p.ID
LEFT JOIN (
SELECT
post_id,
SUM(unique_pageviews) unique_pageviews,
SUM(pageviews) pageviews
FROM
wp_google_views_daily
WHERE
date >= DATE(DATE_SUB(NOW(), INTERVAL 30 day))
GROUP BY post_id
) thirty_days_views ON thirty_days_views.post_id = p.ID
WHERE
p.post_status = 'publish' AND
p.post_password = ''
ORDER BY p.post_date DESC