Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取sql中另一个字段中重复值的计数?_Sql_Database_Ms Access 2007 - Fatal编程技术网

如何获取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;

你在寻找一个正在运行的总计数吗?不,我在寻找重复值的序列