我想通过一些花哨的排名函数对我的 postgres 结果进行排序,但为了简单起见,假设我想添加两个自定义行并按它们排序。
SELECT my_table.*,
extract(epoch from (age(current_date, '2012-09-12 10:43:40'::date)))/3600 AS age_in_hours
Fancy_function_counting_distance() AS distance
FROM my_table
ORDER BY distance + age_in_hours;
但是,它不起作用,因为我收到错误:ERROR: column "distance" does not exist
. 是否可以按自定义命名行对我的结果进行排序?
我正在运行 postgres 9.1.x