Quickest Badge Earners (v1.0)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Open Source Meta

Q&A about the site for people organizing, marketing or licensing open source development projects

--A short revamp of polygenelubricants' "Quickest badge earners V2c" since I am unable to figure out why it is not
--returning for some badges.
--OG: https://data.stackexchange.com/stackoverflow/query/10418/quickest-badge-earners-v2c

--hmmm doesnt work, idk why.
DECLARE @firsttime DATE
SELECT @firsttime = MIN(Badges.DATE) FROM Badges WHERE Badges.Id = '1'
;
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 [Days Membership]
   FROM Badges
   INNER JOIN Users ON Badges.UserId = Users.Id
   WHERE Badges.Id = '1'
   )
SELECT *,DATEDIFF(DAY,@firsttime,[Date Won]) AS [DaysSince1st]
FROM BadgeEarners
ORDER BY [Date Won] ASC

Enter Parameters

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