Question: Normalization and SQL Join Need sql for: Display all customer. If a customer has placed any orders, also display the highest unit price in any
Normalization and SQL Join
Need sql for:
Display all customer. If a customer has placed any orders, also display the highest unit price in any order of the customer. Otherwise, display null. We want to know each customers highest price item ever ordered. Show customerId, customerName, and the highest unit price in any order of that customer
| CustomerID | CustomerName | Highest Unit Price |
| 1 | Just Electronics | 1599.99 |
| 2 | Beyond Electronics | 1449.99 |
| 3 | Beyond Electronics | 1499.99 |
| 4 | E Fun | 99.99 |
| 5 | Overstock E | 999.99 |
| 6 | E Fun | NULL |
| 7 | Electronics4U | 79.99 |
| 8 | Cheap Electronics | NULL |
My sql is not correct
Select CustomerID, CustomerName, Max(Price) AS "Highest Unit Price"
FROM Sales.Customers JOIN Sales.Orders
ON Sales.CustomerID = Sales.CustomerID
RIGHT JOIN Sales.OrderDetail
ON Sales.CustomerId = Sales.CustomerID
Group BY OrderID

Sales.customers Columns Customerld (PK, int, not null) CustomerName (nvarchar(50) StreetAddress (nvarchar(50), n City (nvarchar(20), null) State (nvarchar(20), null) B PostalCode (nvarchar(10), nul Country (nvarchar(20), null) Contact (nvarchar(50), nul) Email (nvarchar(50), null) DKeys Constraints Triggers Indexes Statistics Sales.OrderDetails Columns Orderld (PK, FK, int, not null) Productld (PK, FK, int, not nul) Price (money, not null) Equantity (smallint, not null) Keys Constraints Triggers Indexes Statistics
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
