如何在Access查询中根据排序值添加序号 [英] How to add sequenced number based on sorted value in query in Access

查看:105
本文介绍了如何在Access查询中根据排序值添加序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回一些值的查询 (att1).我还希望在它旁边有表示 att1 排序顺序的值.像这样:

I have a query which returns some values (att1). I would like also to have next to it the values which would represent a sorted order of att1. Something like this:

att1   att2
 19     3
 2      2
 46     4
 78     5
 1      1

这样做的解决方案或正确方法是什么?

What would be the solution or the right approach to do this?

推荐答案

假设表名为 table1,下面应该会产生想要的结果:

Assuming a table name of table1, The following should yield the desired result:

select a.att1, (select count(*) from table1 b where b.att1 <= a.att1) as att2
from table1 a;

对于每条记录,查询计算小于或等于当前记录的记录数,然后作为排序索引输出.

For every record, the query calculates the number of records less than or equal to the current record, which is then output as the sort index.

这篇关于如何在Access查询中根据排序值添加序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆