我正在查看是否可以在Access Query中运行计数。
我在TeamName
TeamName
----------
Liverpool
Liverpool
Liverpool
Liverpool
Liverpool
Manchester
Manchester
Newcastle
Newcastle
Stoke
Stoke
Stoke
我想在Access中使用一个按时间顺序计算出现次数的公式,如下所示
TeamName Count
-------- -----
Liverpool 1
Liverpool 2
Liverpool 3
Liverpool 4
Liverpool 5
Manchester 1
Manchester 2
Newcastle 1
Newcastle 2
Stoke 1
Stoke 2
Stoke 3
答案 0 :(得分:1)
由于您没有任何可用于订购具有相同名称的团队名称的列,因此您必须首先添加此类列:
ALTER Table YourTable ADD TeamID AUTOINCREMENT(1,1);
现在您的表格中有一个数字ID,您可以在查询中使用相同名称对项目进行排名,如下所示:
select
teamname,
(select count(*)
from yourtable as t2
where t1.teamid > t2.teamid
and t1.teamname = t2.teamname
) + 1 as rank
from yourtable t1;