Badges that less than 1% of users have that you don't have

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @usrid int = ##UserId##

select "Badge Name", "Percent" from
(
  select x.m AS "Badge Name", (convert(decimal,x.n)/y.n)*100 AS "Percent" from 
  (
 
    SELECT COUNT(UserID) AS n, Name AS m FROM Badges 
        WHERE TagBased = 0 AND
        UserID <> @usrid GROUP BY Name

  ) x join
  (
  
    SELECT DISTINCT COUNT(AccountId) AS n FROM Users

  ) y on 1=1 
) AS Foo

where Foo."Percent" < 1 ORDER BY "Percent" ASC

Enter Parameters

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