Q&A about the site for administrators, end users, developers and designers for Craft CMS
Select PostId, count(posthistory.Id) as 'before' from posthistory inner join posts on posts.id = posthistory.postid where posthistory.creationdate<= posts.CommunityOwnedDate and posthistorytypeid in (1,4,5,6,7,8,9) and postId in (select PostId from posthistory inner join posts on posts.id = posthistory.postid where posthistorytypeid = 16 and posts.posttypeid=1) group by Postid