With con as ( SELECT distinct p.owneruserid, DATEPART(Yea...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

With con as (
SELECT distinct
  p.owneruserid,
  DATEPART(Year, p.creationdate) as year,
  CASE 
    WHEN sum(CASE WHEN p.posttypeid in (1,2) AND  DATEPART(Month, p.creationdate) in (1,2,3) THEN 1 END) IS NULL
    THEN
        CASE WHEN sum(CASE WHEN DATEPART(Month, c.creationDate) in (1,2,3) THEN 1 END) IS NULL
        THEN 0 ELSE 1 END    
    ELSE 1 END
  +
  CASE 
    WHEN sum(CASE WHEN p.posttypeid in (1,2) AND  DATEPART(Month, p.creationdate) in (4,5,6) THEN 1 END) IS NULL
    THEN
        CASE WHEN sum(CASE WHEN DATEPART(Month, c.creationDate) in (4,5,6) THEN 1 END) IS NULL
        THEN 0 ELSE 1 END    
    ELSE 1 END
  +
  CASE 
    WHEN sum(CASE WHEN p.posttypeid in (1,2) AND  DATEPART(Month, p.creationdate) in (7,8,9) THEN 1 END) IS NULL
    THEN
    CASE WHEN sum(CASE WHEN DATEPART(Month, c.creationDate) in (7,8,9) THEN 1 END) IS NULL
        THEN 0 ELSE 1 END    
    ELSE 1 END
  +
  CASE 
    WHEN sum(CASE WHEN p.posttypeid in (1,2) AND  DATEPART(Month, p.creationdate) in (10,11,12) THEN 1 END) IS NULL
    THEN
    CASE WHEN sum(CASE WHEN DATEPART(Month, c.creationDate) in (10,11,12) THEN 1 END) IS NULL
        THEN 0 ELSE 1 END    
    ELSE 1 END
    as consectiveTotal
FROM Posts p
inner join Comments C on C.UserId = p.owneruserid 
WHERE p.owneruserid = 5 and DATEPART(year, p.creationdate) >= 2010 AND DATEPART(year, p.creationdate) <= 2020 
GrOUP by p.owneruserid, DATEPART(Year, p.creationdate)
)

SELECT
  con.owneruserid
FROM con
group by con.owneruserid
--having sum(con.consectiveTotal) = 132

Enter Parameters

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