Logarithmic vote distribution by month

1

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

DECLARE @Ts DATETIME;

SELECT @Ts = DATEFROMPARTS(
  YEAR(MAX(Votes.CreationDate)),
  MONTH(MAX(Votes.CreationDate)),
  1)
FROM Votes;

SELECT
  DATEFROMPARTS(
    YEAR(Votes.CreationDate),
    MONTH(Votes.CreationDate),
    1) AS Month,
  MIN(VoteTypes.Name) AS VoteType,
  LOG(COUNT(*))/LOG(2) AS Log2Count
FROM Votes, VoteTypes
WHERE
  Votes.VoteTypeId = VoteTypes.Id
  AND
  Votes.CreationDate < @Ts
GROUP BY
  DATEFROMPARTS(
    YEAR(Votes.CreationDate),
    MONTH(Votes.CreationDate),
    1),
  Votes.VoteTypeId
ORDER BY Month DESC, Log2Count DESC

Enter Parameters

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