我希望能够为所有问题运行总计的赞成票。时间戳是CreationDate,但它只在总变化时返回值。
Declare @UserId int;
Select @UserId = ##UserId:int##;
With
upvotedQuestions As (
Select v.CreationDate,
Sum(Count(1)*5) Over (Order By v.CreationDate) As Score
From Posts p
Inner Join Votes v
On v.PostId = p.id
Where v.VoteTypeId = 2 -- is an upvote
And p.PostTypeId = 1 -- is a question
And p.OwnerUserId = @UserId
Group By v.CreationDate
)
Select distinct
v.CreationDate,
upvotedQuestions.Score As [Upvote Question]
From Votes v
Left Outer Join upvotedQuestions On upvotedQuestions.CreationDate =v.CreationDate
Where v.CreationDate >= (
Select CreationDate
From Users
Where id = @UserId
)
Order By v.CreationDate
;