Median comment length for user

1

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

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 sites:
loading Hold tight while we fetch your results