Median comment length for user

1

Please login or register to vote for this query.

(click on this box to dismiss)

Cognitive Sciences Meta

Q&A about the site for practitioners, researchers, and students in cognitive science, psychology, neuroscience, and psychiatry

DECLARE @UserId int = ##UserId:int##


DECLARE @c BIGINT = (SELECT COUNT(*) FROM Comments WHERE UserId = @UserID)

SELECT AVG(1.0 * CommentLength)
FROM (
  SELECT LEN(Text) as CommentLength FROM Comments WHERE UserId = @UserID
     ORDER BY LEN(Text)
     OFFSET (@c - 1) / 2 ROWS
     FETCH NEXT 1 + (1 - @c % 2) ROWS ONLY
) AS x;

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results