Dynamic Count of items +/- 15% per row value I have a table with a column of building sizes named "SQFT".  I trying to find the number of buildings that are within 15% +/- of each rows "SQFT" value.
I have tried case, count with filter and window functions but none would give me the results I'm looking for, at least not in the way I was using them.  

Below is what I'd like as a final result.  

ID   -15%    SQFT    +15%    COUNT
1    85      100     115     2
2    94      110     127     3
3    102     120     138     3
4    111     130     150     4
5    119     140     161     5
6    128     150     173     5
7    136     160     184     5
8    145     170     196     5
9    153     180     207     5
10   162     190     219     5
11   170     200     230     7
12   179     210     242     7
13   187     220     253     7
14   196     230     265     6
15   204     240     276     5
16   213     250     288     4


This is the code so far:

WITH base AS (
   SELECT "Unique ID" as id, "Sqft Total" AS "SQFT", "Sqft Total" * (1-.15) as low, "Sqft Total" * (1+.15) as high
   FROM   "_KEY_TABLE"
   )
SELECT  
    id,
    round(low::numeric,0) as "-15%",
    sqft,
    round(high::numeric,0) as "+15%",
    count(*) over(partition by "SQFT" between low and high) as "COUNT"
    -- case when "SQFT" between low and high is true then 1 end, 
    -- count(*) filter (where "SQFT" between low and high) as counter_filtered,
FROM   base b
group by b."SQFT", id, low, high
Not sure exactly what you want, but I imagine it's something like this. Here we use a INNER JOIN and check the right table for the range.

-- sample data
WITH t(x) AS (SELECT generate_series(1,10))

SELECT t1.x,
  t1.x*0.85 AS lower, -- just so you can see the lower
  t1.x*1.15 AS upper, -- just so you can see the upper
  count(*)
FROM t AS t1
INNER JOIN t AS t2
  ON t2.x BETWEEN t1.x*0.85 AND t1.x*1.15  -- JOY
GROUP BY t1.x
ORDER BY t1.x;


Output,

 x  | lower | upper | count 
----+-------+-------+-------
  1 |  0.85 |  1.15 |     1
  2 |  1.70 |  2.30 |     1
  3 |  2.55 |  3.45 |     1
  4 |  3.40 |  4.60 |     1
  5 |  4.25 |  5.75 |     1
  6 |  5.10 |  6.90 |     1
  7 |  5.95 |  8.05 |     3
  8 |  6.80 |  9.20 |     3
  9 |  7.65 | 10.35 |     3
 10 |  8.50 | 11.50 |     2
(10 rows)