Vanity: Which users earned a particular tag-based badge sooner than me?

1

Please login or register to vote for this query.

(click on this box to dismiss)

Skeptics

Q&A for scientific skepticism

-- Which users earned a particular tag-based badge sooner than me?

DECLARE @BadgeName nvarchar(255) = '##BadgeName##'
DECLARE @BadgeType int = ##BadgeType## -- 1: Gold, 2: Silver, 3: Bronze
DECLARE @UserId int = ##UserId##

SELECT
Users.DisplayName,
Users.Id,
DATEDIFF(day, Users.CreationDate, Badges.Date) AS Days
FROM Badges
  INNER JOIN Users ON Users.Id = Badges.UserId
WHERE
  Badges.Class = @BadgeType
  AND Badges.TagBased = 1 -- for true
  AND Badges.Name = @BadgeName
  AND DATEDIFF(day, Users.CreationDate, Badges.Date) <=
    (SELECT DATEDIFF(day, Users.CreationDate, Badges.Date)
    FROM Badges
      INNER JOIN Users ON Users.Id = Badges.UserId
    WHERE
      Badges.Class = @BadgeType
      AND Badges.TagBased = 1 -- for true
      AND Badges.Name = @BadgeName
      AND Badges.UserId = @UserId)
ORDER BY Days Asc

Enter Parameters

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