запрос доступа: как запросить, чтобы получить рассчитанные значения? - PullRequest
1 голос
/ 10 декабря 2008

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 ]

2 голосов
/ 10 декабря 2008

Как насчет:

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

Где t - имя большой таблицы.

2 голосов
/ 10 декабря 2008

Предполагая таблицу, подобную этой:

type, code, ... other columns.

Я предполагаю, что ваши первые 2 запроса похожи на

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];

Надеюсь, это поможет. Chris

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...