Anton.Sandbox

0

Please login or register to vote for this query.

(click on this box to dismiss)

Portuguese Language

Q&A for linguists, teachers and learners wanting to discuss the finer points of the Portuguese language

-- At what hour do I add most posts, both questions and answers?
-- UTC (GMT) time zone. The week starts with Sunday.
-- Parameters:
--   HourOrDOW (1 - hours, 2 - day of week, 3 - both)
--   Mine (1 - show for one user, 0 - show stats for all users)
--   UserId

DECLARE @Choice int = ##HourOrDOW:int?1##
DECLARE @All int = ##All:int?1##
DECLARE @UsedId int = ##UserId:int##


IF @Choice = 1
  SELECT
    DATEPART("hour", CreationDate) AS [Hour you add a post],
    COUNT(*) AS [Number of your posts per hour, UTC (GMT)],
    COUNT(case PostTypeId when 1 then 1 else null end) AS [Including questions, UTC (GMT)]
  FROM Posts
  WHERE OwnerUserId = CASE @All WHEN 1 THEN OwnerUserId ELSE @UsedId END
  GROUP BY DATEPART("hour", CreationDate)
ELSE IF @Choice = 2
  WITH tmp AS
    (
    SELECT
      *,
      DATEPART("weekday", CreationDate) AS wpart,
      DATENAME(dw, CreationDate) AS wname
    FROM Posts
    )
  SELECT
    wpart AS [Weekday you add a post],
    -- Little hack to show DoW with data.SO graph builder
    wname,
    COUNT(*) AS [Number of your posts per weekday]
  FROM tmp
  WHERE OwnerUserId = CASE @All WHEN 1 THEN OwnerUserId ELSE @UsedId END
  GROUP BY wpart, wname
  ORDER BY wpart
ELSE IF @Choice = 3
  WITH tmp AS
   (
   SELECT *, ROUND((CAST(DATEPART("weekday", CreationDate) AS float) + CAST(DATEPART("hour", CreationDate) AS float) / 24), 2) AS cd
   FROM Posts
   )
  SELECT
    cd AS [Day of week + time],
    COUNT(*) AS [Number of posts]
  FROM tmp
  WHERE OwnerUserId = CASE @All WHEN 1 THEN OwnerUserId ELSE @UsedId END
  GROUP BY cd
  ORDER BY cd

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results