如何获取sql中另一个字段中重复值的计数?
我有一张桌子如何获取sql中另一个字段中重复值的计数?,sql,database,ms-access-2007,Sql,Database,Ms Access 2007,我有一张桌子 id area Count1 39 AB 40 AB 41 AB 42 AB 82 Ag 83 Ag 98 Ai 100 Ai 183 Am 我需要另一个字段中重复值的计数,比如'count1',因为id很重要 我需要的答案是 id area Count1 39 AB 1 40 AB 2 41 AB 3 42 AB 4 82 Ag 1 83 A
id area Count1
39 AB
40 AB
41 AB
42 AB
82 Ag
83 Ag
98 Ai
100 Ai
183 Am
我需要另一个字段中重复值的计数,比如'count1',因为id很重要
我需要的答案是
id area Count1
39 AB 1
40 AB 2
41 AB 3
42 AB 4
82 Ag 1
83 Ag 2
98 Ai 1
100 Ai 2
183 Am 1
我得到了重复值的计数
目前我正在使用ms access 2007
谢谢您可以使用相关子查询来完成此操作:
select id, area,
(select count(*)
from table as t2
where t2.area = t.area and
t2.id <= t.id
) as Count1
from table as t;
你在寻找一个正在运行的总计数吗?不,我在寻找重复值的序列