SELECT a, Count(DISTINCT 1 + b) BETWEEN 2 AND 3 FROM ( SELECT 1 AS a, 2 AS b ) GROUP BY a ;