Not mentioning the RDBMS, lets say MS SQL
SELECT TopicID,
COUNT(1) TotalCount
FROM TopicComments
WHERE CommentDate BETWEEN @StartDate AND @EndDate
GROUP BY TopicID
ORDER BY TotalCount DESC
So a full example would look something like
DECLARE @TopicComments TABLE(
TopicID INT,
UserID INT,
CommentDate DATETIME
)
INSERT INTO @TopicComments SELECT 1, 1, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 1, 1, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 1, 2, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 1, 2, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 2, 1, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 2, 1, '14 Feb 2010'
INSERT INTO @TopicComments SELECT 2, 2, '05 Feb 2010'
DECLARE @StartDate DATETIME,
@EndDate DATETIME
SELECT @StartDate = '10 Feb 2010',
@EndDate = '14 Feb 2010'
SELECT TopicID,
COUNT(1) TotalCount
FROM @TopicComments
WHERE CommentDate BETWEEN @StartDate AND @EndDate
GROUP BY TopicID
ORDER BY TotalCount DESC
Results
TopicID TotalCount
----------- -----------
1 4
2 2
To select the TOP 1 would then be
SELECT TOP 1
TopicID,
COUNT(1) TotalCount
FROM @TopicComments
WHERE CommentDate BETWEEN @StartDate AND @EndDate
GROUP BY TopicID
ORDER BY TotalCount DESC
EDIT
Use somthing like
DECLARE @StartDate DATETIME,
@EndDate DATETIME
SET @EndDate = DATEADD(D, 0, DATEDIFF(D, 0, GETDATE())) --returns only the date part of GETDATE()
SET @StartDate = @EndDate - 5