I have a query that returns two rows:
SELECT *
FROM (
SELECT cola,colb from table LIMIT 2
) as f
Result is:
cola, colb
x, 1
y, 2
Is it possible to use the results in the top level SELECT? Similar to:
SELECT some_function(x,y), some_other_function(1,2)
FROM (
SELECT cola,colb from table LIMIT 2
) as f
Here is the actual query:
SELECT *
FROM
(
SELECT
alt,
st_distance_sphere(
st_closestpoint(geom,st_setsrid(st_makepoint(x,y),4326)),
st_setsrid(st_makepoint(x,y),4326)
) as d
FROM table
) as foo
It returns:
alt | d
800 | 9.658
900 | 11.59
etc