WITH weeks(week) AS ( SELECT DISTINCT datepart(year, Crea...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Space Exploration

Q&A for spacecraft operators, scientists, engineers, and enthusiasts

WITH
  weeks(week) AS (
    SELECT DISTINCT datepart(year, CreationDate) * 100 
                  + datepart(week, CreationDate)
    FROM Posts
    WHERE OwnerUserId = ##UserId##
  ),
  groups AS (
    SELECT
      ROW_NUMBER() OVER (ORDER BY week) AS rn,
      (week -ROW_NUMBER() OVER (ORDER BY week)) AS grp,
      week
    FROM weeks
  )
SELECT
  COUNT(*) AS consecutiveWeeks
FROM groups
GROUP BY grp
ORDER BY 1 DESC

Enter Parameters

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