Question or answer score over time

0

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

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
--select s1.date, s2.score as DCShannon, s3.score as badp
--from score_ot s1
--left join score_ot s2 on s1.date = s2.date and s2.postId = 11468
--left join score_ot s3 on s1.date = s3.date and s3.postId = 11472

Enter Parameters

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