0

我想查看一个日期范围内销售的总产品数量,即

 -------------------------
 |  PRODUCT   | QUANTITY |
 -------------------------
 |   A        |    120   |
 -------------------------
 |   B        |     75   |
 -------------------------

我在MS Access 2003中有以下 sql 查询:

SELECT Product, Sum(PurchaseQuantity) AS Quantity
FROM tblInvoice
GROUP BY Product
HAVING PurchaseDate BETWEEN #3/19/2013# and #3/22/2013#;

但这没有执行。MS Access 给我错误,例如:

“您尝试执行的查询不包含指定表达式‘PurchaseDate BETWEEN #3/19/2013# and #3/22/2013#’作为聚合函数的一部分。”

到目前为止,我知道我需要在 Group By 子句中添加 PurchaseDate 。但是有没有办法在不将 PurchaseDate 放在 Group By 子句中的情况下做到这一点?

先感谢您。

4

1 回答 1

3

您应该在“WHERE”子句中使用 purchaseDate 条件:

SELECT Product, Sum(PurchaseQuantity) AS Quantity 
FROM tblInvoice
WHERE PurchaseDate BETWEEN #3/19/2013# and #3/22/2013#
GROUP BY Product
于 2013-03-24T08:00:24.510 回答