Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions SQL_exercise_01/1_questions_and_solutions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,17 @@ ORDER BY price ASC


-- 1.16 Select the name of each manufacturer along with the name and price of its most expensive product.
select max_price_mapping.name as manu_name, max_price_mapping.price, products_with_manu_name.name as product_name
from
(SELECT Manufacturers.Name, MAX(Price) price
FROM Products, Manufacturers
WHERE Manufacturer = Manufacturers.Code
GROUP BY Manufacturers.Name)
as max_price_mapping
left join
(select products.*, manufacturers.name manu_name
from products join manufacturers
on (products.manufacturer = manufacturers.code))
as products_with_manu_name
on
(max_price_mapping.name = products_with_manu_name.manu_name
and
max_price_mapping.price = products_with_manu_name.price);
SELECT Products.Name as "Products Name",
Products.Price as "Price",
Manufacturers.Name as "Manufacture Company"
from Products,Manufacturers
where Products.Manufacturer = Manufacturers.Code
and Products.Price =
(
select max(Products.Price)
from Products
where Products.Manufacturer = Manufacturers.Code
);



Expand Down