代码之家  ›  专栏  ›  技术社区  ›  OldBuildingAndLoan Caffé

Access db loop-为一个表中的每条记录在另一个表中创建记录数组

  •  1
  • OldBuildingAndLoan Caffé  · 技术社区  · 17 年前

    是否可以在中创建嵌套循环查询 这将更新第三个表吗?

    ------------------------
    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
    
    1 回复  |  直到 17 年前
        1
  •  1
  •   shahkalpesh    17 年前
    
    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