Quickest badge earners V2cV1

0

Please login or register to vote for this query.

(click on this box to dismiss)

Now addresses the fact that some badges aren't even introduced until a certain date, so some members couldn't have gotten it any sooner since they aren't applied retroactively. Added 1 plus DateDiff (OBOE)

スタック・オーバーフロー

プログラマーとプログラミングに熱心な人々のための質問と回答

-- Quickest badge earners V2b
-- Now addresses the fact that some badges aren't even introduced until a certain date, so some members couldn't have gotten it any sooner since they aren't applied retroactively.
-- Added 1 plus DateDiff (OBOE)

DECLARE @firstTime date
SELECT @firstTime = min(Badges.Date) FROM Badges WHERE Badges.Id = '##BadgeName##'
;
WITH BadgeEarners AS (
   SELECT
      Users.Id as [User Link],
      Users.CreationDate as [Member Since],
      Badges.Date as [Date Won],
      1+DateDiff(Day, Users.CreationDate, Badges.Date) As [DaysMembership]
   FROM
     Badges
     INNER JOIN Users
     ON Badges.UserId = Users.Id
   WHERE
     Badges.Id = '##BadgeName##'
)

SELECT
   *, DateDiff(Day, @firstTime, [Date Won]) As [DaysSince1st]
FROM BadgeEarners
ORDER BY
   [DaysMembership] ASC

Enter Parameters

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