Question: How to Fix the code given below so that it can satisfy the questions below: a. List all customer zip codes (wither they have an

How to Fix the code given below so that it can satisfy the questions below:

a. List all customer zip codes (wither they have an order or not)

b. Count the number of customers in that zip

c. Count the number of orders for that zip

d. Calculate the total spent in that zip

e. Sort the result by the most profitable zips (Total and # of customers)

USE tempdb

SELECT COUNT(DISTINCT C.CustomerID) AS CountOfCustomers, ---Add Count of Number of Orders SUM(OL.Quantity X OL.UnitPrice) AS OrderTotal, C.PostalPostalCode FROM Sales.Orders O INNER JOIN Sales.OrderLines OL ON OL.OrderID = O.OrderID INNER JOIN Sales.Customers ON C.CustomerID = O.CustomerID GROUP BY OL.PostalPostalCode ORDER BY PostalPostalCode DESC ;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!