按列别名过滤(firebird sql)

时间:2014-02-21 20:56:32

标签: sql firebird firebird2.5

我制作了一个名为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

但我也希望显示距离。

帮助?

1 个答案:

答案 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