@SergeySafaryanc

Sql-ex какие особенности у проверочной бд «Компьютерная фирма»?

Добрый день, решаю задачки с сайта sql-ex.ru и вот уже несколько дней ломаю голову над 75 задачкой, вроде бы задачка не сложная, но 2 проверочная база говорит об обратном)

Изначально я джойнил каждую таблицу с таблицей Product
select 
	maker,
	max(l.price) as laptop,
	max(pc.price) as pc,
	max(r.price) as printer
from 
	Product t
	left join Laptop l 
		on t.model=l.model
	left join PC 
		on t.model=pc.model
	left join Printer r 
		on t.model=r.model
group by 
	maker

Не принял

После, решил объединить таблицы
with
	B as (
		select 
			p.maker, p.type, max(a.price) 
		from 
			Product p 
			inner join (
				select distinct model, price from Laptop
				union
				select distinct model, price from PC
				union
				select distinct model, price from Printer
			) a 
			on 
				p.model=a.model 
		group by 
			p.maker, p.type
		)

select 
	b1.maker,
	coalesce((select max from B where maker=b1.maker and type='Laptop'), null) as Laptop,
	coalesce((select max from B where maker=b1.maker and type='PC'), null) as PC,
	coalesce((select max from B where maker=b1.maker and type='Printer'), null) as Printer
from 
	B b1
group by 
	b1.maker

Что тоже было отвергнуто проверочной базой)

Вопрос, что я забыл учесть, какая особенность у проверочной бд "Компьютерная фирма"?
  • Вопрос задан
  • 1675 просмотров
Решения вопроса 1
@BorisKorobkov
Web developer
Вы забыли условие "... у которых есть продукты с известной ценой хотя бы в одной из таблиц..."

То есть надо:
select 
  maker,
  max(l.price) as laptop,
  max(pc.price) as pc,
  max(r.price) as printer
from 
  Product t
  left join Laptop l 
    on t.model=l.model
  left join PC 
    on t.model=pc.model
  left join Printer r 
    on t.model=r.model
group by 
  maker
having
	max(l.price) IS NOT NULL
	OR max(pc.price) IS NOT NULL
	OR max(r.price) IS NOT NULL
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы