· 8 years ago · Jun 13, 2018, 01:36 AM
1drop table if exists r1;
2drop table if exists r2;
3drop table if exists r3;
4
5create table r1(detail, blank, material); -- шифр детали, шифр заготовки, материал
6create table r2(detail, shop); -- шифр детали, цех
7create table r3(material, number); -- материал, количеÑтво
8
9-- 1. Детали, которые ÑвлÑÑŽÑ‚ÑÑ Ñборочными единицами
10select detail
11from r1
12group by detail
13having count(distinct blank) > 1;
14
15-- 2. Детали, которые изготавливаютÑÑ Ð²Ð¾ вÑех цехах
16select r2.detail
17from r2
18group by detail
19having count(distinct shop) = (select count(distinct shop) from r2);
20
21-- 3. Детали, которые изготавливаютÑÑ Ñ‚Ð¾Ð»ÑŒÐºÐ¾ в одном цехе
22select r2.detail
23from r2
24group by detail
25having count(distinct shop) = 1;
26
27-- 4. Детали, которые в данный момент можно запуÑкать в производÑтво (Ñ‚.е. Ð´Ð»Ñ ÐºÐ¾Ñ‚Ð¾Ñ€Ñ‹Ñ… еÑть на Ñкладе материалы)
28select distinct r1.detail
29from r1 where r1.detail not in (select r1.detail from r1 natural join r3 where r3.number = 0);
30
31-- 5
32select r2.shop
33from r2 where r2.shop not in (select r2.shop from r1 natural join r2 where r1.material = 'ДЮРÐЛЮМИÐИЙ КЕМ БЫ ТЫ ÐЕ БЫЛ');