One option would be to use derived table:
SELECT dis FROM
(SELECT DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) as dis
FROM CURR_LOCATION)
WHERE dis < 5000 ORDER BY dis
Question
I made a UDF called DistanceMeters which returns the distance between two coordinates as an integer. Now I want to use it to filter the results, for example,
SELECT DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) as dis
FROM CURR_LOCATION where dis < 5000 ORDER by dis
The problems is that I can't refer to the column alias in the where condition:
SQL error code = -206
Column unknown
DIS
This will work:
SELECT * FROM CURR_LOCATION where DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) < 5000
but I want to show the distance as a result too.
Help?
Solution
One option would be to use derived table:
SELECT dis FROM
(SELECT DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) as dis
FROM CURR_LOCATION)
WHERE dis < 5000 ORDER BY dis