Q&A for people studying math at any level and professionals in related fields
--reate table #posts(body nvarchar(max), -- repcategory tinyint) -- create index #idx_posts on #posts(repcategory) select posts.body , case when Reputation < 15 then 1 when reputation between 15 and 50 then 2 else 3 end as repcategory into #posts from Users inner join posts on posts.owneruserid = users.id WHERE Users.Reputation < 100 and posttypeid = 2 select choose( repcategory, 'None', 'FlagOnly', 'FlagAndComment') AS Privilege, Count(*) [PrivilegeCount] from #posts where body like '%stackoverflow%' and (body like '%http:%' or body like '%https:%') group by repcategory