Consider the following pageviews (left) and daterange (right) tables:
_date pageviews _date
--------------------- ----------
2011-01-01 21331 2011-01-01
2011-01-02 32143 2011-01-02
2011-01-04 23434 2011-01-03
. .
. .
2011-08-30 32322 2011-08-30
The table contains dates with corresponding website pageviews. Notice there are days without any pageviews (such as 2011-01-03).
What I need is a query to count the total number of pageviews per day of the month. So it should add the number of pageviews of januari 1st + februari 1st + … + november 1st as the first value, then januari 2 + februari 2 + … februari 3 as the second value. The output of the query wuld thus be 31 days (numbered 1 to 31) with corresponding total number of pageviews.
I have no clue on how to begin. I have created a daterange table holding all dates between 2011-01-01 and 2011-08-30 to be able to CAOLESCE and return 0 for days missing in the pageviews table. But I’m quite lost from there onwards.
Do you know how to solve this? Any help is greatly appreciated 🙂
Hope the above query will solve the problem.