WITH
input_query as(
SELECT
*
FROM airports
order by cartodb_id asc
limit 1000
),
moran as(
SELECT
*
FROM cdb_crankshaft.CDB_AreasOfInterestLocal(
'SELECT * FROM airports order by cartodb_id asc limit 1000',
'elevation_ft',
'knn',
5,
99,
'the_geom',
'cartodb_id')
)
SELECT input_query.*, moran.*
FROM
input_query,
moran
WHERE moran.rowid = input_query.cartodb_id