From 8ed076dd0213cf877df147e358ece70a7dc6a826 Mon Sep 17 00:00:00 2001 From: Danny Date: Wed, 9 May 2018 08:34:58 +0200 Subject: [PATCH] use correct groupby parameter for aggregated stats --- pkg/datastore/page_stats.go | 2 +- pkg/datastore/referrer_stats.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/datastore/page_stats.go b/pkg/datastore/page_stats.go index 4fa3db7..232567f 100644 --- a/pkg/datastore/page_stats.go +++ b/pkg/datastore/page_stats.go @@ -30,7 +30,7 @@ func UpdatePageStats(s *models.PageStats) error { func GetAggregatedPageStats(startDate time.Time, endDate time.Time, limit int) ([]*models.PageStats, error) { var result []*models.PageStats - query := dbx.Rebind(`SELECT hostname, pathname, SUM(pageviews) AS pageviews, SUM(visitors) AS visitors, SUM(entries) AS entries, ROUND(AVG(bounce_rate), 0) AS bounce_rate FROM daily_page_stats WHERE date >= ? AND date <= ? GROUP BY hostname, pathname, pageviews, visitors, entries, bounce_rate ORDER BY pageviews DESC LIMIT ?`) + query := dbx.Rebind(`SELECT hostname, pathname, SUM(pageviews) AS pageviews, SUM(visitors) AS visitors, SUM(entries) AS entries, ROUND(AVG(bounce_rate), 0) AS bounce_rate FROM daily_page_stats WHERE date >= ? AND date <= ? GROUP BY hostname, pathname ORDER BY pageviews DESC LIMIT ?`) err := dbx.Select(&result, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), limit) return result, err } diff --git a/pkg/datastore/referrer_stats.go b/pkg/datastore/referrer_stats.go index 01a0d97..15b2e80 100644 --- a/pkg/datastore/referrer_stats.go +++ b/pkg/datastore/referrer_stats.go @@ -31,7 +31,7 @@ func UpdateReferrerStats(s *models.ReferrerStats) error { func GetAggregatedReferrerStats(startDate time.Time, endDate time.Time, limit int) ([]*models.ReferrerStats, error) { var result []*models.ReferrerStats - query := dbx.Rebind(`SELECT url, SUM(visitors) AS visitors, SUM(pageviews) AS pageviews FROM daily_referrer_stats WHERE date >= ? AND date <= ? GROUP BY url, visitors, pageviews ORDER BY pageviews DESC LIMIT ?`) + query := dbx.Rebind(`SELECT url, SUM(visitors) AS visitors, SUM(pageviews) AS pageviews FROM daily_referrer_stats WHERE date >= ? AND date <= ? GROUP BY url ORDER BY pageviews DESC LIMIT ?`) err := dbx.Select(&result, query, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"), limit) return result, err }