MS Access 查询问题
我正在尝试计算有多少产品与我们的每个女性客户相关,以便我可以在以后的计算中使用它。
SELECT [Customers].Customer_ID
FROM [Customers]
WHERE ((([Customers].Gender)='Female'))
GROUP BY [Customers].Customer_ID;
上面的 SQL 为我提供了女性客户的 ID 列表。现在,我想在一个单独的查询中,我需要计算上面列表中每个 ID 的产品 ID 数量,但我不知道从哪里开始。我不知道是否可以将此步骤合并到上面的查询中,或者我是否需要做其他事情。
我想我需要这样的东西:
DCount("Order_ID", "Orders", "Customer_ID = [**how do I make it to where
this equals the resulting Customer_ID's from the above query**]" )
有人可以帮忙吗?我走在正确的轨道上吗?
如果您需要更多信息,请告诉我。
I am trying to count how many products are associated with each of our female customers so I can use it in a later calculation.
SELECT [Customers].Customer_ID
FROM [Customers]
WHERE ((([Customers].Gender)='Female'))
GROUP BY [Customers].Customer_ID;
The above SQL gives me a list of ID's for our female customers. Now, I guess in a separate query, I need to count the number of Product ID's for each of the ID's in the above list, but I don't know where to go from here. I don't know if I can combine this step into the above query, or if I need to do something else.
I am thinking I need something like this:
DCount("Order_ID", "Orders", "Customer_ID = [**how do I make it to where
this equals the resulting Customer_ID's from the above query**]" )
Can someone please help? Am I on the right track?
If you need more info, please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类似于:
INNER JOIN
应更改为LEFT JOIN
以包含没有任何订单的客户(以及COUNT(*) 应更改为
COUNT(Orders.Customer_ID)
as @onedaywhen saw):注意,上述查询将为您提供订单数量 而不是数量正如您所描述的产品。您必须提供表格的结构(可能是
Orders
或OrderDetails
如果您有这样的表格),以便我们知道有关产品(及其订单)的信息在哪里) 被存储。旁注:(再次,值得超过一半的分数:)@onedaywhen发现,
Customer_ID
应该是表[Customers]的
。如果是这种情况(或者如果它是PRIMARY KEY
UNIQUE
),则您的原始查询可以简化:Something like:
The
INNER JOIN
should be changed intoLEFT JOIN
to include Customers without any Orders (andCOUNT(*)
should be changed toCOUNT(Orders.Customer_ID)
as @onedaywhen spotted):Note, that the above queries will give you number of Orders and not number of Products as you describe. You'll have to provide the structure of the tables (probably
Orders
, orOrderDetails
if you have such a table) so we know where the information about products (and their orders) is stored.Sidenote: as (again, deserving more than half of these points :) @onedaywhen spotted, the
Customer_ID
is supposed to be thePRIMARY KEY
of table[Customers]
. If that's the case (or if it isUNIQUE
), your original query could be simplified:试试这个。
由于我在这台电脑上没有 MS Access,因此尚未对其进行测试。
类似的东西在 MySQL 和 MS SQL 中工作,所以它可能工作:)
Try this.
Haven't tested it since I don't got MS Access on this PC.
Similar stuff work in MySQL and MS SQL so it might work :)