Skip to content
Advertisement

How to Create SELECT for Total sales for each region

I want to write a query to get Total sales for every region, but i cant figure the way to do it. I have these tables:

Region(RegionID, Name)
Client(ClientID, Name, City, Country, Email, RegionID)
Order(OrderID, Orderdate, ClientID)
Orderdetail(OrderID, ProductID, Quantityordered, Quantitydelivered)
Product(ProductID, Name, UnitPrice)

Advertisement

Answer

First join all the tables, and sum the quantity. Try this:

    SELECT r.Name AS RegionName, TotalQuantityOrdered = SUM(od.Quantityordered), TotalQuantityDelivered = SUM(Quantitydelivered) 
    FROM Orderdetail od
    INNER JOIN Order o on od.OrderID = o.OrderID
    Inner join Client c on o.ClientID = c.ClientID
    Inner Join Region r on c.RegionId = r.RegionId
    Group By r.Name
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement