Question or answer score over time

0

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 @vote_data table
(
    PostId int
    ,ID int
    ,date date
    ,score_change int
);

insert into
    @vote_data
select
    v.PostId
    ,v.Id
    ,v.CreationDate
    ,case vt.Id
        when 2 then 1
        when 3 then -1
        end
from
    Votes v
    join VoteTypes vt on vt.Id = v.VoteTypeId
where
    v.PostId in (11468, 11472)
    and vt.Id in (2, 3);

with score_ot as (
select
    v1.PostId
    ,min(v1.date) as date
    ,sum(v2.score_change) as score
from
    @vote_data v1
    join @vote_data v2 on v2.Id < v1.Id
group by
    v1.PostId, v1.Id
    )
    select * from score_ot

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results