簡體   English   中英

從兩個表生成 SQL 查詢 (MS Access)

[英]Generate SQL Query From Two Tables (MS Access)

我的數據庫中有兩個表

臨時存儲訂單表

|ID|Date Product Was Made|RecipeID|  Recipe Name  |ProductID|Product Name|
 1   November 10th, 2015    1       100LB S Batch    1         Saltbread
 2   November 10th, 2015    2       100LB B Batch    2         Bran Fruit

食譜表

 |RecipeID|   Recipe Name   |ProductID|Product Name|ItemID| Item |Amount
     1       100LB S Batch       1      Saltbread     213   Salt   100
     1       100LB S Batch       1      Saltbread     56    Sugar   60
     2       100LB B Batch       2      Bran Fruit    213   Salt    34
     2       100LB B Batch       2      Bran Fruit    56    Sugar   12

我想實現的是一個查詢表顯示

ItemID | Item |      Date Used      | Amount | ProductID | Product Name |
  213    Salt   November 10th, 2015    100         1         Saltbread
  56     Sugar  November 10th, 2015     60         1         Saltbread
  213    Salt   November 10th, 2015     34         2         Bran Fruit
  56     Sugar  November 10th, 2015     12         2         Bran Fruit

在 MS Access 中實現此結果的 SQL 代碼是什么

這將是您的查詢:

--Iso is Interim Storage Orders Table
--Rec is Recipes Table
--As stated in query

SELECT Rec.ItemID, Rec.Item, Iso.DateProductWasMade, 
Rec.Amount, Iso.ProductID, Iso.ProductName
FROM Recipes AS Rec
INNER JOIN InterimStorageOrders AS Iso ON Rec.ProductID = Iso.ProductID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM