declare @start nvarchar(10) = ##start:string?2019-11-01##...

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 @start nvarchar(10) = ##start:string?2019-11-01## 
declare @end nvarchar(10) = ##end:string?2020-11-01## 

select count(*) [1. all posted]
from postswithdeleted
where creationdate 
between @start
and     @end
and posttypeid = 1 -- Q

select count(*) [2. deleted]    
from postswithdeleted
where deletiondate 
between @start
and     @end
and posttypeid = 1 -- Q


select count(*) [3. undeleted]    
from postswithdeleted pwd
where deletiondate 
between @start
and     @end
and posttypeid = 1 -- Q
and exists (select 1 from votes where postid = pwd.id and votetypeid = 11)

select count(*) [4. undeleted again]    
from postswithdeleted pwd
where deletiondate 
between @start
and     @end
and posttypeid = 1 -- Q
and exists (select 1 
            from votes ud
            inner join votes d on d.postid = ud.postid 
            where ud.postid = pwd.id and ud.votetypeid = 11
            and d.votetypeid = 10
            and d.creationdate > ud.creationdate)

Enter Parameters

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