我正在創建一個從多個表中選擇數據的查詢。我已完成所有查詢,但現在必須將WHERE
子句應用於整個查詢。 我有9選擇語句,這些工作正常。數據正在從不同的表中選擇。現在我想聲明日期session
,我希望根據提供的日期過濾所有數據。我使用下面的查詢:如何將WHERE子句應用於SQL Server中的多個SELECT語句
SELECT
(SELECT COUNT(DISTINCT OrderItems.ProductID)
FROM OrderItems) AS 'TotalSoldItemsDistinct',
(SELECT COUNT(OrderItems.ProductID)
FROM OrderItems) AS 'TotalSoldItemsInDistinct',
(SELECT COUNT(Orders.OrderID)
FROM Orders) AS 'TotalOrders',
(SELECT COUNT(Orders.OrderID)
FROM Orders
WHERE Orders.OrderStatusID = @CompleteOStatusID) AS 'CompleteOrders',
(SELECT COUNT(Orders.OrderID)
FROM Orders
WHERE Orders.OrderStatusID = @PendingOStatusID) AS 'PendingOrders',
(SELECT COUNT(Orders.ClientID)
FROM Orders
WHERE Orders.ClientID != @WalkingCustID) AS 'namedcustomers',
(SELECT COUNT(Orders.ClientID)
FROM Orders
WHERE Orders.ClientID = @WalkingCustID) AS 'WalkingCustomers',
(SELECT SUM(OrderItems.PurchasePrice)
FROM OrderItems) AS 'TotalPurchasePrice',
(SELECT SUM(OrderItems.SalePrice)
FROM OrderItems) AS 'TotalSalePrice'
我選擇從2個表數據名爲「Orders
」和「OrderItems
」,我有「訂單」表和列OrderDate
列TransactionDate
在OrderItems
表上,我想使用過濾器。任何人都可以建議如何應用過濾器到整個查詢?
還有比這裏解決您的問題..你的查詢可以更簡化 – maSTAShuFu
感謝回覆更多。將ü請建議我該怎麼做? –
你將不得不尋找一個類似的情況下,或等到有人,因爲我現在要回家:) – maSTAShuFu