1

此查询生成一个客户 ID 表:

SELECT Transactions.customerId
FROM Transactions 
WHERE Transactions.purchaseDate <#9/1/2012#
GROUP BY Transactions.customerId
HAVING  Sum(Transactions.amountPaid)<>0;

此查询生成事务表:

SELECT Customers.firstName, Customers.lastName, Transactions.transactionId, Transactions.product, Transactions.purchaseDate, Transactions.amountPaid, Customers.customerId
FROM Customers INNER JOIN Transactions ON Customers.customerId = Transactions.customerId
WHERE (((Transactions.refundTransaction)=False));

我想仅从第一个查询生成的用户中选择所有事务(第二个查询)。

4

1 回答 1

3

使用 MS Access,可以保存这两个查询,然后按查询名称将它们添加到查询设计窗口。添加后,您可以通过将相关字段名称从一个拖放到另一个来在两个查询之间创建一个 INNER JOIN。下一个阶段,如果可以继续,是用查询名称替换派生表,即查询的 sql 内容。

例如:

查询1

SELECT ID, CustName FROM Table1 WHERE SomeField > 2

查询2

SELECT CustID, TranName FROM Table2 WHERE SomeField > Date()

查询3

SELECT * FROM Query1 INNER JOIN Query2 ON Query1.ID = Query2.CustID

替代:

SELECT * FROM (
   SELECT ID, CustName 
   FROM Table1 
   WHERE SomeField > 2) As Q1
INNER JOIN (
   SELECT CustID, TranName 
   FROM Table2 WHERE SomeField > Date()) As Q2
ON Q1.ID = Q2.CustID
于 2012-09-30T16:06:19.230 回答