Q&A for science fiction and fantasy enthusiasts
-- S1 : Lower limit on Score (including) -- S2 : Upper limit on Score (excluding) -- V2 : Upper limit on Views (excluding) -- dV : ViewCount bin size -- Index = (Score - Lower limit on Score) * Number of View bins + View bin index -- View bin index = Index % Number of View bins -- Score = Index / Number of View bins + Lower limit on Score DECLARE @NV int = ##V2## / ##dV## -- number bins in viewcounts SELECT sel.Idx, Count(*) as [Occurence] FROM (SELECT (Score - ##S1##) * @NV + ViewCount / ##dV:int?10## as [Idx] FROM Posts WHERE PostTypeId = 1 -- questions and Score >= ##S1:int?-5## and Score < ##S2:int?45## and ViewCount < ##V2:int?4000##) sel GROUP BY sel.Idx ORDER BY sel.Idx