Select l.n_det from p l where l.res<=
(select avg(res) from p) and l.n_det in
(select d.n_det from spj d where d.n_izd=k.n_izd))
- Найти все номера изделий, для которых поставляются только детали с весом не выше среднего.
- Найти все номера изделий, для которых существуют поставки деталей только с весом выше среднего
25) select * from j where not n_izd in (select n_izd from spj where
not n_post in (select n_post from s where reiting<
(select avg(reiting) from s)))
выбрать все записи для изделий, рейтинги поставщиков которых меньше среднего
26) запросы:
select distinct table4.n_post,table1.name from table4,table1 where
table4.n_post=table1.n_post and
(select count(distinct one.n_isdel) from table4one where
one.n_det=table4.n_det and
table4.n_post=one.n_post)=
(select count(n_isdel) from table3)
select n_isdel from table3 where not exists
(select n_post from table4 x where n_det in
(select n_det from table2 where color=’Красный’ and
not exists (select * from table4 y where y.n_post and y.n_isdel=table3.n_isdel)
select n_post,n_del,n_isdel from table1,table2,table3 where
table1.town=table2.town and table1.town=table3.town
select n_post from table4 where n_det in
(select n_det from table2 where color=’Красный’)
into temp tt; update table4 set kolvo=1.1*kolvo where
n_post in (select n_post from tt)
create table table_new(color char(20),town char(20));
insert into table_new select distinct color,town from table2
27) №10 select distinct n_post from spj spjx where exists
(select n_det from p where not exists
(select n_izd from j where not exists
(select * from spj spjz where spjz.n_post=spjx.n_post
and spjz.n_det=p.n_det and spjz.n_izd=j.n_izd)))
выдать перечень поставщиков(без повторов), которые поставляют деталь(какую-либо) для всего перечня изделий.
28) Триггер №5: Отслеживается изменение индекса изделия в таблице изделий если изделие с таким индексом не существует, то изменение каскадируются на таблицу поставок, если изделие существует, то операция отвергается.
Create trigger name_tr update on j
Referencing old as old_zn new as new_zn
For each row
execute procedure name_proc(old_zn.rowid,old_zn.izd_n,new_zn.izd_n)
create procedure name_proc(int r_id,int old_id,int new_id)
define cnt integer;
let cnt=(select count(*) from j where izd.n=new_id)
if cnt!=1 then update j set izd_n=old_id where rowid=r_id
else update spj set izd_n=new_id where izd.n=old_id
end if; end procedure
29) №10 select distinct p.n_det,p_name from spj,p
where p.n_det=spj.n_det and spj.n_post
(select distinct tmp.n_post from spj as tmp,j where
(select distinct count(*) from spj where
spj.n_post=tmp.n_post and spj.n_det=tmp.n_det
and spj.n_izd in(select n_izd from j where town=’Атенс’))=
=(select count(*) from j where town='Атенс') and
spj.n_izd in(select n_izd from j where town='Атенс'
Выбрать номера деталей, название поставляемых таким поставщиком, что он поставляет детали для всех изделий из Атенс.
30) №11 select distinct n_izd from spj t1 where exists( select n_det from spj t2 where n_post=’S1’ and t1.n_izd=t2.n_izd) union select n_izd from spj t3 where(select count(*)/(select count(*) from s) from spj t3)>(select count(*) from spj t5 where t5.n_izd=t3.n_izd)
выводит имя изделий, детали для которых поставляет S1 и количество поставок деталей для каждого из изделий < среднего количества поставок для всех изделий.
31) №22 select x.n_izd from s where not exists
(select y.n_det from spj y where y.n_post=’S2’ and not exists
(select z.n_det,z.n_izd from spj z where z.n_det=y.n_det and
z.n_izd=x.n_izd and z.n_post=’S2’))
Перечень изделий, для которых S2 поставляет все детали, имеющиеся в своем списке поставок.
32) №16(6) Отслеживать модификацию поля «кол-во» в таблице spj, если в результате новое кол-во по величине >30% объема поставок деталей, раньше выполненных этим же поставщиком, то рейтинг поставщика в таблице S увеличивается на 10%.
Create trigger T update kol on spj before (execute procedure p1())
After(execute procedure p2())
Create procedure p1()
Create teble temp(n_det char(6), kol_p int);
insert into temp(n_det,kol_p) select n_post,sum(kol) from spj group by n_post; end procedure
create procedure p2()
update s set reiting=reiting*1.1 where n_post in(select temp.n_post from temp where kol_p*0.7<(select sum(kol) from spj where spj.n_post = temp.n_post;
drop table temp; end procedure
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.