0

I have 4 tables

Order(OrderId,OrderDate,Firm,ConsumerId)
OrderProductDetails(OrderId,ProductId,Firm,Quantity,Rate,Fulfilled,PendingQuantity) [fulfilled is boolean]
Product(ProductId,ProductName)
Consumer(ConsumerId,ConsumerName)

I want to fetch those orders (OrderId,OrderDate,ConsumerName) that are not completely fulfilled. I tried a lot, but wasn't able to make it work. The query seems simple, but I do not know how complex it is gonna be.

4

2 回答 2

1

根据您提供的信息,以下应该有效。

select order.orderid, order.orderdate, consumers.consumername
from order
inner join orderproductdetails on orderproductdetails.orderid = order.orderid
inner join consumers on consumers.consumerid = order.consumerid
where orderproductdetails.fulfilled = 0 

我假设您有一个“消费者”表,并且布尔值“假”由值 0 表示。

于 2013-09-12T06:45:48.360 回答
0

以下查询应该可以正常工作。
注意:
1)我已将 Order 表重命名为 OrderT,
2)重命名 Consumer -> ConsumerT

SELECT DISTINCT OrderProductDetails.OrderId, OrderT.OrderDate, ConsumerT.ConsumerName FROM OrderProductDetails, ConsumerT INNER JOIN OrderT ON ConsumerT.ConsumerId = OrderT.ConsumerId WHERE (([OrderProductDetails].[Fulfilled]=0) AND ([OrderProductDetails].[OrderId] =[OrderT].[OrderId]));

查询背后的逻辑是:您希望数据主要来自两个表 OrderT 和 ConsumerT。但是所有数据都取决于 OrderProductDetails.Fulfilled,最后一个是未完成的订单,只需要那些消费者姓名。创建查询时的 MS Access 设计视图有很大帮助。

于 2013-09-12T07:29:53.737 回答