Q&A for ebook publishers and readers
SELECT pp.MentionsInjection , SUM(case when v.votetypeid = 2 then 10 when v.votetypeid = 3 then -2 else null end) / COUNT(distinct pp.id) AS RepGain FROM tags t JOIN posttags pt ON pt.tagid = t.id JOIN ( select * , case when body like '%asdsad%' then 1 else 0 end as MentionsInjection from posts ) pp ON pp.id = pt.postid JOIN posts pa ON pa.parentid = pp.id JOIN votes v ON v.postid = pa.id WHERE t.tagname = 'sql' GROUP BY pp.MentionsInjection