Skip to content

Update 1_questions_and_solutions.sql #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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