prateeksharma

DBMS_Lab_05_Assignment

Sep 25th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1.  
  2. create table College(cName varchar2(10) primary key, state
  3. varchar2(10), enrollment int);
  4. create table Student(sID int primary key, sName varchar2(10), GPA
  5. real, sizeHS int);
  6. create table Apply(sID int, cName varchar2(10), major varchar2(20),
  7. decision char(1), primary key(sID, major, cName), constraint sID_fk
  8. Foreign key(sID) references Student, constraint cName_fk Foreign
  9. key(cName) references College);
  10. delete from Student;
  11. delete from College;
  12. delete from Apply;
  13. insert into Student values (123, 'Amy', 3.9, 1000);
  14. insert into Student values (234, 'Bob', 3.6, 1500);
  15. insert into Student values (345, 'Craig', 3.5, 500);
  16. insert into Student values (456, 'Doris', 3.9, 1000);
  17. insert into Student values (567, 'Edward', 2.9, 2000);
  18. insert into Student values (678, 'Fay', 3.8, 200);
  19. insert into Student values (789, 'Gary', 3.4, 800);
  20. insert into Student values (987, 'Helen', 3.7, 800);
  21. insert into Student values (876, 'Irene', 3.9, 400);
  22. insert into Student values (765, 'Jay', 2.9, 1500);
  23. insert into Student values (654, 'Amy', 3.9, 1000);
  24. insert into Student values (543, 'Craig', 3.4, 2000);
  25. insert into College values ('Stanford', 'CA', 15000);
  26. insert into College values ('Berkeley', 'CA', 36000);
  27. insert into College values ('MIT', 'MA', 10000);
  28. insert into College values ('Cornell', 'NY', 21000);
  29. insert into College values ('Harvard', 'MA', 50040);
  30. insert into Apply values (123, 'Stanford', 'CS', 'Y');
  31. insert into Apply values (123, 'Stanford', 'EE', 'N');
  32. insert into Apply values (123, 'Berkeley', 'CS', 'Y');
  33. insert into Apply values (123, 'Cornell', 'EE', 'Y');
  34. insert into Apply values (234, 'Berkeley', 'biology', 'N');
  35. insert into Apply values (345, 'MIT', 'bioengineering', 'Y');
  36. insert into Apply values (345, 'Cornell', 'bioengineering', 'N');
  37. insert into Apply values (345, 'Cornell', 'CS', 'Y');
  38. insert into Apply values (345, 'Cornell', 'EE', 'N');
  39. insert into Apply values (678, 'Stanford', 'history', 'Y');
  40. insert into Apply values (987, 'Stanford', 'CS', 'Y');
  41. insert into Apply values (987, 'Berkeley', 'CS', 'Y');
  42. insert into Apply values (876, 'Stanford', 'CS', 'N');
  43. insert into Apply values (876, 'MIT', 'biology', 'Y');
  44. insert into Apply values (876, 'MIT', 'marine biology', 'N');
  45. insert into Apply values (765, 'Stanford', 'history', 'Y');
  46. insert into Apply values (765, 'Cornell', 'history', 'N');
  47. insert into Apply values (765, 'Cornell', 'psychology', 'Y');
  48. insert into Apply values (543, 'MIT', 'CS', 'N');
  49.  
  50.  
  51. select sID,sName from student where sid in(select sid from apply where major='CS' and apply.sid=student.sid);
  52.  
  53. select sID,sName from student where sizeHS in(select sizeHS from student where sName='Jay');
  54.  
  55. select sID,sName from student where sizeHS in(select sizeHS from student where sName='Jay') and sName not in 'Jay' ;
  56.  
  57. select sID,sName,GPA from student where GPA not in (select GPA from student where sName='Irene');
  58.  
  59. select distinct cName from Apply where sID in(select sID from student where sName like 'J%');
  60.  
  61. select major from Apply where sID in (select sID from Student where sName='Irene');
  62.  
  63. select distinct sID,major from Apply where major in (select major from Apply where sid in (select sid from student where sName='Irene'));
  64.  
  65. select distinct sID,major from Apply where major in (select major from Apply where sid in (select sid from student where sName='Irene')) and not in 876;
  66.  
  67. select count(distinct (cName)) from Apply where sid in (select sid from student where sname='Jay');
  68.  
  69. select * from student where sid in (select sid from apply where major='CS') and sid not in (select sid from apply where major='EE');
  70.  
  71. select cname from college where state in (select state from college group by state having count(cname>1);
  72.  
  73. select cname from college where enrollment in (select max(enrollment) from college);
  74.  
  75. select sname from student where gpa in (select min(gpa) from student );
  76.  
  77. select major from apply group by major having count(major) in (select max(count(major)) from apply group by major);
  78.  
  79. select sid, sname, sizeHS from student where sizeHS not in (select min(sizeHS) from student);
Add Comment
Please, Sign In to add comment