Guest User

Untitled

a guest
Sep 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. drop table Enrollment;
  2. drop table Offering;
  3. drop table Course;
  4. drop table Student;
  5. drop table Instructor;
  6. drop table Person;
  7.  
  8. USE db363anha0404;
  9.  
  10. -- item 1 Create table Person
  11. create table Person (
  12. Name char (20),
  13. ID char (9) not null,
  14. Address char (30),
  15. DOB date,
  16. Primary Key (ID));
  17.  
  18. -- item 2 Create table Instructor
  19. create table Instructor (
  20. InstructorID char (9) not null references Person (ID),
  21. Rank char (12),
  22. Salary int,
  23. primary key (InstructorID) );
  24.  
  25. -- item 3 Create table Student
  26. create table Student (
  27. StudentID char (9) not null,
  28. Classification varchar (10),
  29. GPA double, MentorID char (9) references Instructor (InstructorID),
  30. CreditHours int);
  31.  
  32. -- item 4 Create table Course
  33. create table Course (
  34. CourseCode char (6) not null,
  35. CourseName char (50),
  36. PreReq char (6));
  37.  
  38. -- item 5 Create table Offering
  39. create table Offering (
  40. CourseCode char (6) not null,
  41. SectionNo int not null,
  42. InstructorID char (9) not null references Instructor (InstructorID),
  43. primary key (CourseCode, SectionNo));
  44.  
  45. -- item 6 Create table Enrollment
  46. create table Enrollment (
  47. CourseCode char(6) NOT NULL,
  48. SectionNo int NOT NULL,
  49. StudentID char(9) NOT NULL references Student,
  50. Grade char(4) NOT NULL,
  51. primary key (CourseCode, StudentID),
  52. foreign key (CourseCode, SectionNo) references Offering(CourseCode, SectionNo));
  53.  
  54. /* Item 7-12 - Load Person, Instructor, Student, Course, Offering, and Enrollment tables. */
  55. -- item 7
  56. load xml local infile '/home/ahan37/Documents/ComS363/Person.xml'
  57. into table Person
  58. rows identified by '<Person>';
  59.  
  60. -- item 8
  61. load xml local infile '/home/ahan37/Documents/ComS363/Instructor.xml'
  62. into table Instructor
  63. rows identified by '<Instructor>';
  64.  
  65. -- item 9
  66. load xml local infile '/home/ahan37/Documents/ComS363/Student.xml'
  67. into table Student
  68. rows identified by '<Student>';
  69.  
  70. -- item 10
  71. load xml local infile '/home/ahan37/Documents/ComS363/Course.xml'
  72. into table Course
  73. rows identified by '<Course>';
  74.  
  75. -- item 11
  76. load xml local infile '/home/ahan37/Documents/ComS363/Offering.xml'
  77. into table Offering
  78. rows identified by '<Offering>';
  79.  
  80. -- item 12
  81. load xml local infile '/home/ahan37/Documents/ComS363/Enrollment.xml'
  82. into table Enrollment
  83. rows identified by '<Enrollment>';
  84.  
  85. -- item 13
  86. select s.StudentID, s.MentorID
  87. from Student s
  88. where (s.GPA > 3.8 and s.Classification = 'junior') or ( s.GPA > 3.8 and s.Classification = 'senior');
  89.  
  90. -- item 14
  91. select distinct e.CourseCode, e.SectionNo
  92. from Enrollment e, Student s
  93. -- where e.StudentID = s.StudentID and s.Classification = 'Sophomore';
  94. where e.StudentID in (select s.StudentID
  95. from Student s
  96. where s.Classification = 'Sophomore');
  97.  
  98. -- item 15
  99. select distinct p.Name, i.Salary
  100. from Person p, Instructor i
  101. where p.ID = i.InstructorID and p.ID in (select s.MentorID
  102. from Student s
  103. where s.Classification = 'Freshman');
  104.  
  105. -- item 16
  106. select sum(i.Salary)
  107. from Instructor i
  108. where i.InstructorID not in (select o.InstructorID from Offering o);
  109.  
  110. -- item 17
  111. select p.Name, p.DOB
  112. from Person p
  113. where Year(p.DOB) = 1976 and p.ID in (select Student.StudentID from Student);
  114.  
  115. -- item 18
  116. select p.Name, i.Rank
  117. from Person p, Instructor i
  118. where p.ID = i.InstructorID and p.ID not in (select Offering.InstructorID from Offering)
  119. and i.InstructorID not in (select Student.MentorID from Student);
  120.  
  121. -- item 19
  122. select p.ID, p.Name, p.DOB
  123. from Person p
  124. where p.DOB = (select max(p.DOB) from Person p)
  125. and p.ID in (select Student.StudentID from Student);
  126.  
  127. -- item 20
  128. select p.ID, p.DOB, p.Name
  129. from Person p
  130. where p.ID not in (select Student.StudentID from Student)
  131. and p.ID not in (select Instructor.InstructorID from Instructor);
  132.  
  133. -- item 21
  134. select p.Name, count(*) as 'NumberofStudents'
  135. from Person p, Instructor i, Student s
  136. where i.InstructorID = p.ID
  137. and s.MentorID = p.ID
  138. and s.MentorID = i.InstructorID
  139. group by p.Name;
  140.  
  141. -- item 22
  142. select count(*) as 'NumberofStudents', avg(s.GPA) as 'Average GPA'
  143. from Student s
  144. group by s.Classification;
  145.  
  146. -- item 23
  147. select e.CourseCode, count(e.CourseCode) as NumberofEnrollment
  148. from Enrollment e
  149. group by e.CourseCode
  150. order by NumberofEnrollment asc
  151. limit 1;
  152.  
  153. -- item 24
  154. select distinct e.StudentID, s.MentorID
  155. from Student s, Enrollment e, Offering o
  156. where e.CourseCode = o.CourseCode
  157. and o.InstructorID = s.MentorID and e.StudentID = s.StudentID;
  158.  
  159.  
  160. -- item 25
  161. select s.StudentID, p.Name, s.CreditHours
  162. from Student s
  163. join Person p on p.ID = s.StudentID
  164. where year(p.DOB) >= 1976
  165. and s.Classification = 'Freshman';
  166.  
  167. -- item 26
  168. insert into Person (Name, ID, Address, DOB)
  169. values ('Briggs Jason','480293439', '215 North Hyland Avenue','1975-01-15 00:00:00');
  170.  
  171. insert into Student (StudentID, Classification, GPA, MentorID, CreditHours)
  172. values ('480293439', 'Junior', 3.48, '201586985', 75);
  173.  
  174. insert into Enrollment (CourseCode, SectionNo, StudentID, Grade)
  175. values ('CS311', 2, '480293439', 'A');
  176.  
  177. insert into Enrollment (CourseCode, SectionNo, StudentID, Grade)
  178. values ('CS330', 1, '480293439', 'A');
  179.  
  180. select *
  181. from Person p
  182. where p.Name= 'Briggs Jason';
  183.  
  184. select *
  185. from Student s
  186. where s.StudentID= '480293439';
  187.  
  188. select *
  189. from Enrollment e
  190. where e.StudentID = '480293439';
  191.  
  192. -- item 27
  193. delete from Enrollment
  194. where StudentID in (select s.StudentID from Student s
  195. where s.GPA < 0.5);
  196.  
  197. delete from Student
  198. where GPA < 0.5;
  199.  
  200. select *
  201. from Student s
  202. where s.GPA < 0.5;
  203.  
  204. -- item 28
  205. update Instructor
  206. set Salary = Salary + (Salary*0.1)
  207. where InstructorID = (select p.ID from Person p
  208. where p.Name = 'Ricky Ponting')
  209. and (select distinct count(*)
  210. from (select * from Instructor) i, Person p, Offering o, Enrollment e, Student s
  211. where p.ID = i.InstructorID
  212. and p.Name = 'Ricky Ponting' and o.InstructorID = i.InstructorID
  213. and e.CourseCode = o.CourseCode and e.StudentID = s.StudentID
  214. and e.Grade = 'A') >= 5;
  215.  
  216. select i.Salary
  217. from Instructor i
  218. where i.InstructorID = (select ID from Person
  219. where Name = 'Ricky Ponting');
  220.  
  221. -- item 29
  222. insert into Person (Name, ID, Address, DOB)
  223. values ('Trevor Horns', '000957303','23 Canberra Street', '1964-11-23 00:00:00');
  224.  
  225. select *
  226. from Person p
  227. where year(p.DOB) = 1964;
  228.  
  229. -- item 30
  230. delete Enrollment, Student from Enrollment
  231. inner join Student on Student.StudentID = Enrollment.StudentID
  232. where Enrollment.StudentID = (select p.ID from Person p
  233. where p.Name = 'Jan Austin');
  234.  
  235. select * from Student
  236. where StudentID = (select p.ID from Person p
  237. where p.Name = 'Jan Austin');
Add Comment
Please, Sign In to add comment