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 p.Id,count(vp.PostId) as fav_total
from Posts p 
left outer join 
(select pp.ParentId,max(pp.CreationDate) as maxcdate
from Posts pp
where pp.PostTypeId=2 
group by pp.ParentId)pa on p.Id=pa.ParentId
left outer join 
(select v.PostId,v.CreationDate 
from Votes v
where v.VoteTypeId=5)vp on p.Id=vp.PostId
where p.PostTypeId=1
and p.Id%500=358
and Year(p.CreationDate)=2019
and vp.CreationDate<maxcdate
group by p.Id

Enter Parameters

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