Created
March 22, 2020 11:59
-
-
Save optozorax/9e043175dc401c416e0f36a6ea47ffbe to your computer and use it in GitHub Desktop.
Защита 6 лаба Базы Данных БД ФПМИ НГТУ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Для каждого изделия найти среди поставлявшихся для него деталей те, | |
-- что имеют наименьшее число поставщиков. Изделия в списке должны быть | |
-- все. Вывести: номер изделия, номер детали, число поставщиков. | |
select jj.n_izd, z.n_det as min_post_izd, z.count as post_count | |
from j jj | |
left join lateral ( | |
select n_det, count | |
from ( | |
select p.n_det, ( | |
select count(distinct n_post) | |
from spj t | |
where t.n_det = p.n_det | |
) count | |
from spj p | |
where p.n_izd = jj.n_izd | |
) t | |
where count = ( | |
select min(( | |
select count(distinct n_post) | |
from spj t | |
where t.n_det = p.n_det | |
)) | |
from spj p | |
where p.n_izd = jj.n_izd | |
) | |
) as z | |
on true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment