Age range on age range in WHERE to heavy - POSTGRES
One approach to improve readability would be to use a CTE to add a couple of calculated columns..  However, this approach could also be slow, depending on the size of the table..  But it would look something like this

WITH true_ages AS (
  SELECT
    &lt;cols&gt;,
    CASE WHEN age_high &lt; age_low THEN age_high -- handle case of 'x and below'
         WHEN age_low = 99 and age_high = 99 THEN 0 -- handle case of 'all ages'
         ELSE age_low END as true_low,
    CASE WHEN age_low &lt; age_high and age_high = 99 THEN 999 -- handle case of 'x and above'
         WHEN age_low = 99 and age_high = 99 THEN 999 -- handle case of 'all ages'
         ELSE age_high END as true_high
  FROM &lt;table&gt;
) SELECT
  &lt;cols&gt;
FROM true_ages
WHERE &lt;target_age&gt; BETWEEN true_low and true_high;


You could potentially add some WHERE clause in the CTE to reduce the result set initially, but that might add unnecessary complexity.