我在處理SQL查詢時遇到困難。我使用PostgreSQL。無法解決此SQL查詢
該查詢顯示:顯示已完成包含來自3個不同類別產品的訂單的客戶。結果將是2列,CustomerID
,以及訂單數量。我寫了這段代碼,但我認爲這不正確。
select SalesOrderHeader.CustomerID,
count(SalesOrderHeader.SalesOrderID) AS amount_of_orders
from SalesOrderHeader
inner join SalesOrderDetail on
(SalesOrderHeader.SalesOrderID=SalesOrderDetail.SalesOrderID)
inner join Product on
(SalesOrderDetail.ProductID=Product.ProductID)
where SalesOrderDetail.SalesOrderDetailID in
(select DISTINCT count(ProductCategoryID)
from Product
group by ProductCategoryID
having count(DISTINCT ProductCategoryID)>=3)
group by SalesOrderHeader.CustomerID;
以下是查詢所需的數據庫表:
你得到一個錯誤? – Matt
不,但根據記錄給出的輸出是不合邏輯 – georgia
http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when問題/ 285557#285557 –