我在MS Access中有一张表格,例如:



+-----+-----+-----+
| 1st | 2nd | 3rd |
+-----+-----+-----+
| A   |   1 | 100 |
| A   |   2 | 200 |
| A   |   3 | 300 |
| B   |   1 | 100 |
| B   |   2 | 200 |
| B   |   3 | 300 |
| C   |   1 | 100 |
| C   |   2 | 200 |
| C   |   3 | 300 |
+-----+-----+-----+

现在,我想从第三列读取值,对其进行某种处理,然后将它们存储到另一个表中,例如:

摘要

+-----+---------+---------+
| 1st |   2nd   |   3rd   |
+-----+---------+---------+
| A   | 100/200 | 200/300 |
| B   | 100/200 | 200/300 |
| C   | 100/200 | 200/300 |
+-----+---------+---------+

换句话说,对于summary.2nd来说,这意味着:
select table.3rd FROM table where table.1st = A AND table.2nd = 1

除以
select table.3rd FROM table where table.1st = A AND table.2nd = 3

有人可以给我提示如何做到吗?

也许VBA / ADO Recordset等?

最佳答案

一种方法是条件聚合:

select [1st],
       max(iif([2nd] = 1, [3rd], null)) / max(iif([2nd] = 2, [3rd], null)) as [2nd],
       max(iif([2nd] = 2, [3rd], null)) / max(iif([2nd] = 3, [3rd], null)) as [3rd]
from t
group by [1st];

08-20 03:55