"The candidates answer your questions.”, different elections, same link

1

Please login or register to vote for this query.

(click on this box to dismiss)

https://meta.stackoverflow.com/questions/364780/the-candidates-answer-your-questions-different-elections-same-link

Stack Overflow

Q&A for professional and enthusiast programmers

select election
     , ph.creationdate 
     , text
from posthistory ph
inner join (
select election
     , min(min_nom) as [earliest]
     , max(max_nom) as [latest]
from
(
  select dense_rank() over(order by max_nom) election
       , id
       , min_nom
       , max_nom
  from
  (
    select pm.id  
         , min(pm.creationdate) min_nom
         , max(pg.creationdate) max_nom
    from posts pm
    inner join posts pg on pg.creationdate 
          between dateadd(d, -16, pm.creationdate)   -- roughly 14 days
             and dateadd(d, +16, pm.creationdate) 
    where pm.posttypeid = 6
    and   pg.posttypeid = 6
    group by pm.id
  ) data
) data_min_max
group by election
) as data_election on ph.creationdate between dateadd(d, -1, earliest) 
                                          and dateadd(d,  7, latest) -- we need some overlap
where ph.postid = 8041931
and ph.posthistorytypeid in (2,5)
order by election

Enter Parameters

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