Q&A for Drupal developers and administrators
WITH cte AS (SELECT Dateadd(week, Datepart(week, creationdate), '1/1/' + CAST(YEAR(creationdate) AS CHAR(4))) cdate, CASE WHEN closeddate IS NOT NULL THEN 1 ELSE 0 END closed, id FROM posts WHERE posttypeid = 1) SELECT cdate, ( CAST(SUM(closed) AS DECIMAL (15, 4)) / CAST(COUNT(id)AS DECIMAL (15, 4)) ) closeRate FROM cte GROUP BY cdate ORDER BY cdate