Created
January 3, 2012 20:30
-
-
Save adrienne/1556779 to your computer and use it in GitHub Desktop.
ExpressionEngine query: count entries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
SUM(entries) AS alltime, | |
SUM(IF((YEAR(entrydate) = YEAR(CURDATE())),entries,0)) AS thisyear, | |
SUM(IF((MONTH(entrydate) = MONTH(CURDATE()) && YEAR(entrydate) = YEAR(CURDATE())),entries,0)) AS thismonth, | |
SUM(IF((WEEKOFYEAR(entrydate) = WEEKOFYEAR(CURDATE()) && YEAR(entrydate) = YEAR(CURDATE())),entries,0)) AS thisweek, | |
SUM(IF((DAYOFYEAR(entrydate) = DAYOFYEAR(CURDATE()) && YEAR(entrydate) = YEAR(CURDATE())),entries,0)) AS thisday | |
FROM | |
(SELECT | |
DATE(FROM_UNIXTIME(entry_date)) AS entrydate, | |
COUNT(entry_id) AS entries | |
FROM exp_channel_titles | |
# You can change the following line if you need to; | |
# you can also add extra conditions in the WHERE clause if you only want to count | |
# entries from certain channels, etc. | |
# SafeToChange | |
WHERE | |
`status` != 'closed' # backticks because "status" is actually a reserved word in MySQL, so it's best to be safe! | |
# End SafeToChange! | |
GROUP BY | |
entrydate | |
) mydatetable | |
; | |
/* -- Example Output: --------------------------------------------------------------------------------- ** | |
| alltime | thisyear | thismonth | thisweek | thisday | | |
| 50000 | 8890 | 350 | 25 | 2 | | |
** ---------------------------------------------------------------------------------------------------- */ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment