Q&A about the site for students, teachers, and linguists wanting to discuss the finer points of the Japanese language
DECLARE @StartDate datetime = '2022-06-20'; DECLARE @EndDate datetime = '2022-10-19'; WITH QuestionViews AS ( SELECT ViewCount, ROW_NUMBER() OVER (ORDER BY ViewCount) AS RowNum, COUNT(*) OVER () AS TotalRows FROM Posts WHERE PostTypeId = 1 -- 1 represents questions AND CreationDate BETWEEN @StartDate AND @EndDate ) SELECT AVG(ViewCount * 1.0) AS MedianViews FROM QuestionViews WHERE RowNum IN ((TotalRows + 1) / 2, (TotalRows + 2) / 2);