### 访问查询：如何查询获取计算值？

HI，

``````type       no of times type occurs
101            450
102            562
103            245
``````

``````code      no of times code occurs
0               1222
1                750
2                355
``````

``````type  no of timescode1occurs %of timescode1 occurs out of  %of times code1 occurs out of
no of times type occurs       no of times code occcurs

101          50                11%                                  6%
102          75                13%                                  10%
``````

#### 2 个答案:

``````type, code, ... other columns.
``````

``````select type, count(*) from mytable group by type

select code, count(*) from mytable group by code
``````

``````SELECT DISTINCTROW mytable.Type, mytable.Code,
Count(*)/q1.[Count of type] AS [Percent Of Type],
Count(*)/q2.[Count of code] AS [Percent Of Code]
FROM mytable,
(select type, count(*) as [Count of type] from mytable group by type) q1,
(select code, count(*) as [Count of code] from mytable group by code) q2
where mytable.Type =q1.Type
and mytable.Code=q2.Code
GROUP BY mytable.Type, mytable.Code, q1.[Count of type], q2.[Count of code];
``````

``````SELECT t.Type, t.Code, COUNT(t.Code) AS CountOfCode,
[CountOfCode]/DCount("Code","t","Code=" & [Code])*100 AS PercentCode,
[CountOfCode]/DCount("Type","t","Type=" & [Type])*100 AS PercentType
FROM t
GROUP BY t.Type, t.Code
``````