在选择查询中,我使用嵌套选择来计算字段。我想按计算得出的字段(排名)对结果进行排序,但是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
[示例查询来自此帖子]
使用派生表
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句