在选择查询中,我使用嵌套选择计算字段。我想按计算字段(排名)对结果进行排序,但 Access 不识别字段排名。 (当我运行查询时,Access 要求输入 rank 的参数值。)
SELECT
*,
(select count(*)
from tbl as tbl2
where tbl.customers > tbl2.customers and tbl.dept = tbl2.dept
) + 1 as rank
FROM tbl
ORDER BY rank
[示例查询取自this发布]
最佳答案
使用派生表
SELECT * FROM
(
SELECT
*,
(select count(*)
from tbl as tbl2
where tbl.customers > tbl2.customers and tbl.dept = tbl2.dept
) + 1 as rank
FROM tbl
) as newtbl
ORDER BY rank
关于sql - 微软 Access : Order by calculated field (using alias),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22782653/