Q&A for professional and enthusiast programmers
select t.tagname , min(t.count) as tc , sum(case when rt.reviewtaskstateid = 3 then 1 else 0 end) as [invalidated] , sum(case when rt.reviewtaskstateid <> 3 then 1 else 0 end) as [validated] , (sum(case when rt.reviewtaskstateid = 3 then 1 else 0 end) *100) / (count(*)) as perc , count(*) as cnt from reviewtasks rt inner join posts p on p.id = rt.postid inner join posttags pt on pt.postid = p.id inner join tags t on t.id = pt.tagid -- inner join posts exc on exc.id = t.excerptPostid where rt.reviewtasktypeid =2 -- close -- and exc.body like '%do not use%' group by t.tagname having sum(case when rt.reviewtaskstateid = 3 then 1 else 0 end) > 0 and sum(case when rt.reviewtaskstateid <> 3 then 1 else 0 end) > 0 and count(*) > 10 and min(t.[count]) > 100 order by (sum(case when rt.reviewtaskstateid = 3 then 1 else 0 end) *100) / count(*) desc