是否可以在 Access DB 中创建一个嵌套循环查询来更新第三个表?

我有一个主(标题)表:

------------------------
masters
------------------------
num | modality | cost  |
------------------------
01  | thing    | 23.00 |
02  | thing    | 42.00 |
03  | thing    | 56.00 |
04  | apple    | 11.00 |
05  | apple    | 17.00 |

和一个临时表,其中包含我需要创建第三个(实际)详细信息表的详细信息,该表将关闭主数据

这是临时详细信息表的示例。

----------------------------------
temps
----------------------------------
modelnumber | modality | priceEa |
----------------------------------
| 123       | thing    | 1.00    |
| 234       | apple    | 2.00    |
| 345       | apple    | 3.00    |
| 456       | apple    | 4.00    |
| 567       | thing    | 5.00    |

基本上,我需要遍历 masters 表中的每条记录。

外圈:

对于masters表中的每条记录,请抓住模态。

内圈:

然后,对于temps表中模态匹配的每条记录,在详细信息表中创建一条记录(在此过程中,根据temps.priceEa和masters.cost进行一些计算)。

这应该在masters表中的每条记录的详细信息表中创建(masters * temps)新记录数。

详细信息表应该看起来像

----------------------------------------------------------
details
----------------------------------------------------------
num  | modelnumber | modality | priceEa  |  adjustedCost |
----------------------------------------------------------
| 01 | 123         | thing     | 1.00    | (do calc here)
| 01 | 567         | thing     | 5.00    | (do calc here)
| 02 | 123         | thing     | 1.00    | (do calc here)
| 02 | 567         | thing     | 5.00    | (do calc here)
| 03 | 123         | thing     | 1.00    | (do calc here)
| 03 | 567         | thing     | 5.00    | (do calc here)
| 04 | 234         | apple     | 2.00    | (do calc here)
| 04 | 345         | apple     | 3.00    | (do calc here)
| 04 | 456         | apple     | 4.00    | (do calc here)
| 05 | 234         | apple     | 2.00    | (do calc here)
| 05 | 345         | apple     | 3.00    | (do calc here)
| 05 | 456         | apple     | 4.00    | (do calc here)
...etc
有帮助吗?

解决方案


SELECT m.num, t.modelnumber, m.modality, t.priceea
into myNewTempTable
from masters m  inner  join temp t on m.modality = t.modality
order by m.num, t.modelnumber

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top