我有一张表analytics_metrics。我正在尝试从最近 x 天的访问者统计和综合浏览量统计中获取计数。日期范围可以更改。
id metrics count date
67 visitorsStatistics 15779 2013-10-10
69 pageviewsStatistics 282141 2013-10-10
90 visitorsStatistics 14588 2013-10-11
92 pageviewsStatistics 265042 2013-10-11
108 pageviewsStatistics 278523 2013-10-12
106 visitorsStatistics 15015 2013-10-12
122 visitorsStatistics 16474 2013-10-13
124 pageviewsStatistics 312752 2013-10-13
138 visitorsStatistics 16829 2013-10-14
140 pageviewsStatistics 320614 2013-10-14
85 pageviewsStatistics 67976 2013-10-15
83 visitorsStatistics 5452 2013-10-15
我希望得到这样的输出:
visitorsStatistics pageviewsStatistics
15779 282141
14588 265042
15015 278523
16474 312752
16829 320614
5452 67976
我已经尝试了 4 个多小时的不同查询,现在我似乎无法找到正确的方法:-(。
这是我到目前为止得到的:
SET @fromDate = '2013-10-10';
set @tillDate = '2013-10-11';
SELECT
*
/* ga_visits.count as visits,
ga_pageviews.count as pageviews
*/
FROM analytics_metrics as ga_visits
LEFT JOIN analytics_metrics as ga_pageviews on (ga_pageviews.date BETWEEN @fromDate AND @tillDate AND ga_pageviews.metrics = 'pageviewsStatistics')
WHERE ga_visits.date BETWEEN @fromDate AND @tillDate AND ga_visits.metrics = 'visitsStatistics'
如果我使用此查询一天,它可以正常工作,但不适用于日期范围。
希望有人可以提供帮助。
先感谢您