Number of User accounts older than Id = 1114

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

-- This is particularly interesting on Meta Stack Overflow, because 
-- there are large gaps of user IDs that were never used due to the
-- way accounts were copied from Stack Overflow. For example, my
-- user ID on Meta Stack Overflow is 134300, but there are only 4266
-- accounts older than mine in the Users table.

DECLARE @UserId int = 1114
DECLARE @CreationDate datetime
DECLARE @LargestUserId TABLE (Id int)
INSERT INTO @LargestUserID SELECT TOP 1 Id FROM Users ORDER BY Id DESC
SELECT @CreationDate = CreationDate FROM Users WHERE Id = @UserId

-- ORDER BY Id DESC

SELECT 'User ID', @UserId
UNION ALL
SELECT 'Older User accounts', COUNT(*)
  FROM Users WHERE CreationDate < @CreationDate
UNION ALL
SELECT 'Lower-IDed User accounts', COUNT(*)
  FROM Users WHERE Id < @UserId
UNION ALL
SELECT '---', NULL
UNION ALL
SELECT 'Largest ID', Id FROM @LargestUserId
UNION ALL
SELECT 'Number of User accounts', COUNT(*)
  FROM Users

-- Fork of http://data.stackexchange.com/stackoverflow/query/100589/number-of-user-accounts-older-than-mine

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached