我制作了一个名为DistanceMeters的UDF,它将两个坐标之间的距离作为整数返回。现在我想用它来过滤结果,例如
SELECT DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) as dis
FROM CURR_LOCATION where dis < 5000 ORDER by dis
问题是我无法在where条件中引用列别名:
SQL error code = -206
Column unknown
DIS
这将有效:
SELECT * FROM CURR_LOCATION where DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) < 5000
但我也希望显示距离。
帮助?
答案 0 :(得分:2)
一种选择是使用派生表:
SELECT dis FROM
(SELECT DistanceMeters("Latitude_C_", "Longitude_C_", 44.894115, -123.031717) as dis
FROM CURR_LOCATION)
WHERE dis < 5000 ORDER BY dis