是否可以在中创建嵌套循环查询
这将更新第三个表吗?
------------------------
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表中的每条记录,获取模态。
内环:
然后,对于temps表中模式匹配的每条记录,在details表中创建一条记录(在此过程中,根据temps.pricea和masters.cost进行一些计算)。
这将为masters表中的每条记录在details表中创建(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