Created
August 11, 2009 01:16
-
-
Save SamSaffron/165561 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
create view UserTotals | |
as | |
select UserId, Reputation, Questions, [Answers], Upvotes, Downvotes from | |
( | |
select | |
UserId = u.Id, | |
u.Reputation as Reputation, | |
sum(case when p.ParentId is null then 1 else 0 end) as Questions, | |
sum(case when p.ParentId is not null then 1 else 0 end) as [Answers] | |
from Users u | |
join Posts p on p.OwnerUserId = u.Id | |
where p.CommunityOwnedDate is null and p.ClosedDate is null | |
group by u.Id, u.Reputation | |
) as t | |
join | |
( | |
select | |
p.OwnerUserId, | |
Upvotes = SUM(case when VoteTypeId = 2 then 1 else 0 end), | |
Downvotes = SUM(case when VoteTypeId = 3 then 1 else 0 end) | |
from Votes v | |
join Posts p on p.Id = v.PostId | |
where VoteTypeId in (2,3) and p.CommunityOwnedDate is null and p.ClosedDate is null | |
group by OwnerUserId | |
) as v on v.OwnerUserId = t.UserId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment