I have 3 tables
1. Orders orderID (PK),clientID,purchesDate,totalPrice
2. OrdersItems orderID (FK),productID (FK),units,price
3. Products productID (PK),mainCategory,subCategory
I have to get the total sum of all products that where sold between two dates
I understand that...
first i have to select the orderIDs that where ordered between the 2 given dates
from the Orders table (cause only in that tabe the dates are written).
SELECT orderId FROM Orders WHERE purchesDate BETWEEN @d1 AND @d2
then I have to get all the productIdDs that the user choosed they are filtered by the user choosing (specific main-category or sub-category. threfore they have to be selected from the Products table.
SELECT productID FROM Products WHERE category = @category
then i have to get from the OrderItems table a list of all productIDs that their orderIDs inner join with orderIDs that I got in the first stage and also are inner joined with the productIDs the user choosed and to SUN the price column for those specific ProductIDs
is it possible to write such a query in one select?
1. Orders orderID (PK),clientID,purchesDate,totalPrice
2. OrdersItems orderID (FK),productID (FK),units,price
3. Products productID (PK),mainCategory,subCategory
I have to get the total sum of all products that where sold between two dates
I understand that...
first i have to select the orderIDs that where ordered between the 2 given dates
from the Orders table (cause only in that tabe the dates are written).
SELECT orderId FROM Orders WHERE purchesDate BETWEEN @d1 AND @d2
then I have to get all the productIdDs that the user choosed they are filtered by the user choosing (specific main-category or sub-category. threfore they have to be selected from the Products table.
SELECT productID FROM Products WHERE category = @category
then i have to get from the OrderItems table a list of all productIDs that their orderIDs inner join with orderIDs that I got in the first stage and also are inner joined with the productIDs the user choosed and to SUN the price column for those specific ProductIDs
is it possible to write such a query in one select?
Last edited: