실험 5 보기 의 정의,사용 실험

2709 단어 데이터 뱅 크
-- 1.    “IS”         V_IS      ;
create view V_IS as
select * from student
where sdept='IS'
with check option ;
/*
drop view v_IS;
create view V_IS as
select * from student
where sdept='IS';
*/
-- select *from v_IS;
-- 2.   S,C,SC       ,  ,   ,   ,       V_S_C_G     ;
-- drop view V_S_C_G;
create view V_S_C_G as
select sno,sname,cno,cname,grade
from sc join student using(sno)
join course using(cno);
SELECT *from v_s_c_g;
-- 3.         ,         V_NUM_AVG     ;
create VIEW V_NUM_AVG as
select Sdept,count(sno) from student
group by sdept;
SELECT * from v_num_avg;
-- 4.                 V_YEAR     ;
create view V_YEAR as
select sno,year(now())-sage as Birthyear 
from student;
select *from v_year;
-- 5.                        V_AVG_S_G     ;
-- drop view V_AVG_S_G;
create view V_AVG_S_G as
select sno,count(cno),avg(grade) as avg_grade 
from sc join student using(sno)
group by sno;
SELECT * from v_avg_S_G;
-- 6.                      V_AVG_C_G     ;
create view V_AVG_C_G as
select cno,count(*) as cnum,avg(grade) avg_grade
from sc group by cno;
select *from V_AVG_C_G;
-- 7.         90        、     ;
SELECT sno,sname,avg_grade from v_avg_S_G
join student using(sno)
where avg_grade>=90 ;
-- 8.                    、  、     ;
SELECT sno,sname,cno,grade from sc a
join student using(sno)
where not exists (
	select * from sc b join v_avg_c_g using(cno)
	where a.Grade< v_avg_c_g.avg_grade and a.Cno=b.Cno
);
-- 9.             80      ,       ;
select sdept,count(*) num 
from  student join v_avg_s_g using(sno)
where avg_grade > 80 
group by sdept
order by num desc;
-- 10.    V_IS,      “200215121” “200215124”        “S1_MMM”,”S4_MMM”      ;
update V_IS set sno='S1_MMM' where sno='200215121'; --       CS ,      
update V_IS set sno='S4_MMM' where sno='200215124';
select *from v_is;
select *from student;
select *from sc;
select *from v_s_c_g;
-- 11.    V_IS,          ('S12','YAN XI',19,'IS'),     ;
insert into V_IS(sno,sname,sage,sdept) values('S12','YAN XI',19,'IS');
-- 12.    V_IS,          ('S13','YAN XI',19,'MA'),     ;
--         MA  ,  check           .
insert into v_is(sno,sname,sage,sdept) values('S13','YAN XI',19,'MA');
-- 13.    V_IS,     “S12” “S13”     ,     ;
--   s13  is ,      
delete from v_is where sno='S12' or sno='S13' ;
-- 14.     V_S_C_G,    “200215124”     “200215124_MMM”,      ?
update v_s_c_g set sname='200215124_MMM' where sno='200215124';
-- 15.     V_AVG_S_G,    “S1”       90 ,      ?
--     ,           ,              ,
--             ,      ,    

좋은 웹페이지 즐겨찾기