Question or answer score over time

1

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
(
    ID int
    ,date date
    ,score_change int
)

insert into
    @vote_data
select
    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
    PostId = ##PostId:int##
    and vt.Id in (2, 3)

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

Enter Parameters

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