我在 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 |
+-----+-----+-----+
现在我想从第 3 列读取值,对其进行某种操作并将它们存储到另一个表中,例如:
总结
+-----+---------+---------+
| 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];
关于sql - 划分顺序记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54605446/