SELECT 数据表.H, Count(数据表.H) AS H计数, DCount("T","数据表","T=" & [H]) AS T计数, DCount("N","数据表","N=" & [H]) AS N计数, [H计数]+[T计数]+[N计数] AS 合计
FROM 数据表
GROUP BY 数据表.H;
如果是统计两个0之间的数据可以这样写:
SELECT first(ID) AS 起始码, count(*)-1 AS 计数
FROM [SELECT a.ID, a.H, (select count(*) from 数据表 as b where b.H=0 and b.ID<=a.ID) AS 分组
FROM 数据表 AS a]. AS c
WHERE c.分组>0
GROUP BY c.分组;
这个查询也可以看成两个查询:
1、查询1:
SELECT a.ID, a.H, (select count(*) from 数据表 as b where b.H=0 and b.ID<=a.ID) AS 分组
FROM 数据表 AS a
2、查询2:
SELECT first(ID) AS 起始码, count(*)-1 AS 计数
FROM 查询1 AS c
WHERE c.分组>0
GROUP BY c.分组;