MS Access中的SQL GROUP BY和MIN

时间:2016-03-11 13:31:25

标签: sql ms-access-2010

我想组合2个表,我想使用GROUP BY并在表格中的每个字段中选择MIN值 我有2个表:TransactionDB和Product

TransactionDB =是列出交易清单的地方

 ProductName                 RemainingStocks
 --------------------------------------------  
 Euphorbia 90 capsules       100  
 Euphorbia 90 capsules       99  

产品=产品清单

 ProductName                 RemainingStocks
 --------------------------------------------  
 Euphorbia 90 capsules       99  
 Lemongrass Tea              100

我使用INSERT INTO语句将记录从Product Table插入到TransactionDB表

           INSERT INTO Inventory ( ProductName, RemainingStocks )
           SELECT ProductName, RemainingStocks
           FROM Product;

产品表变为

ProductName                 RemainingStocks
--------------------------------------------  
Euphorbia 90 capsules       100  
Euphorbia 90 capsules       99 
Euphorbia 90 capsules       99  
Lemongrass Tea              100

使用GROUP BY SELECT对剩余库存的产品名称和MIN进行分组

               SELECT ProductName,MIN(RemainingStocks)
               FROM TransactionDB
               GROUP BY ProductName;

产品表变为

ProductName                 Expr101
--------------------------------------------  
Euphorbia 90 capsules       100  
Euphorbia 90 capsules       99   
Lemongrass Tea              100

我想要这样......帮助

ProductName                 RemainingStocks
--------------------------------------------   
Euphorbia 90 capsules       99   
Lemongrass Tea              100

0 个答案:

没有答案