Created
September 8, 2010 23:37
-
-
Save SamSaffron/571062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select b.Id as BadgeId, b.Name as BadgeName, u.UserId, p.Id as PostId, pv.CreationDate | |
into #upvotes | |
from Badges b | |
join Users2Badges u on u.BadgeId = b.Id | |
join Posts p on p.OwnerUserId = u.UserId and p.CommunityOwnedDate is null and p.DeletionDate is null | |
join Posts2Votes pv on pv.DeletionDate is null and pv.PostId = p.Id and pv.VoteTypeId = 2 | |
join PostTags pt on pt.Tag = b.Name and p.ParentId = pt.PostId | |
where Class = 3 and TagBased = 1 | |
go | |
WITH Enumerated AS ( | |
SELECT BadgeName, UserId, CreationDate, ROW_NUMBER() OVER (PARTITION BY BadgeName, UserId ORDER BY CreationDate asc) AS RN | |
FROM #upvotes | |
) | |
update u | |
set [Date] = data.CreationDate | |
from Users2Badges u | |
join Badges b on b.Id = u.BadgeId | |
join | |
(select * from Enumerated where RN = 100) as data | |
on data.UserId = u.UserId and b.Class = 3 and b.TagBased = 1 and b.Name = data.BadgeName | |
go | |
WITH Enumerated AS ( | |
SELECT BadgeName, UserId, CreationDate, ROW_NUMBER() OVER (PARTITION BY BadgeName, UserId ORDER BY CreationDate asc) AS RN | |
FROM #upvotes | |
) | |
update u | |
set [Date] = data.CreationDate | |
from Users2Badges u | |
join Badges b on b.Id = u.BadgeId | |
join | |
(select * from Enumerated where RN = 400) as data | |
on data.UserId = u.UserId and b.Class = 2 and b.TagBased = 1 and b.Name = data.BadgeName | |
go | |
WITH Enumerated AS ( | |
SELECT BadgeName, UserId, CreationDate, ROW_NUMBER() OVER (PARTITION BY BadgeName, UserId ORDER BY CreationDate asc) AS RN | |
FROM #upvotes | |
) | |
update u | |
set [Date] = data.CreationDate | |
from Users2Badges u | |
join Badges b on b.Id = u.BadgeId | |
join | |
(select * from Enumerated where RN = 1000) as data | |
on data.UserId = u.UserId and b.Class = 1 and b.TagBased = 1 and b.Name = data.BadgeName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment