SELECT e.entryId, e.title, e.preview,
DATE_FORMAT(e.publicationDate, '%m/%d/%Y') as publicationDate,
e.publicationDate as publicationDateTime,
e.views, c.categoryId, c.name as categoryName,
u.firstName, u.lastName, e.disableComments,
count(DISTINCT m.commentId) as commentCount,
Round(e.totalRating/e.timesRated) as averageRating
FROM Entry as e LEFT JOIN EntryCategory as ec
ON e.entryId = ec.entryId
LEFT JOIN Category as c
ON ec.categoryId = c.categoryId
JOIN User as u
ON e.postedByUserId = u.userID
LEFT JOIN Comment as m
ON e.entryId = m.entryId
WHERE e.publicationDate <= now()
AND c.categoryId =
AND MONTH(e.publicationDate) =
AND YEAR(e.publicationDate) =
AND DateDiff(now(), e.publicationDate) <=
GROUP BY e.entryId, e.title, e.preview,
DATE_FORMAT(e.publicationDate, '%m/%d/%Y'),
e.publicationDate,
e.views, c.categoryId, c.name,
u.firstName, u.lastName, e.disableComments
ORDER BY e.publicationDate DESC
SELECT e.entryId, e.title, Round(e.totalRating/e.timesRated) as averageRating
FROM Entry as e
ORDER BY averageRating DESC
LIMIT 0, #arguments.limit#
SELECT e.entryId, e.title, e.views
FROM Entry as e
ORDER BY e.views DESC
LIMIT 0, #arguments.limit#
SELECT e.entryId, e.title, count(c.commentId) as comments
FROM Entry as e JOIN Comment as c
ON e.entryId = c.entryId
GROUP BY e.entryId, e.title
ORDER BY comments DESC
LIMIT 0, #arguments.limit#