select count(*) count , sum(upvotes) upvotes , sum(downv...

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

select  count(*) count
, sum(upvotes) upvotes
, sum(downvotes) downvotes
, sum(case when closeddate is not null then 1 else 0 end) closed
, sum(case when comment is not null then 1 else 0 end) duplicate
from
(
select sum(case when v.votetypeid = 2 then 1 else 0 end) as upvotes
     , sum(case when v.votetypeid = 3 then 1 else 0 end) as downvotes
     , p.closeddate
     , p.id
     , ph.comment
from posts p
inner join posttags pt on pt.postid = p.id
inner join tags t on t.id = pt.tagid
inner join votes v on v.postid = p.id
left outer join posthistory ph on ph.postid = p.id and ph.posthistorytypeid = 10 and comment =101
where posttypeid =1 -- Q
and t.tagname = 'php'
and v.votetypeid in (2,3)
and p.creationdate > '2017-01-01'
group by p.id, p.closeddate, ph.comment
)  data

Enter Parameters

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