Advertisement
Guest User

Untitled

a guest
Dec 6th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. -- Database: "Lab7"
  2.  
  3. -- DROP DATABASE "Lab7";
  4.  
  5. CREATE DATABASE "Lab7"
  6. WITH OWNER = postgres
  7. ENCODING = 'UTF8'
  8. TABLESPACE = pg_default
  9. LC_COLLATE = 'English_United States.1252'
  10. LC_CTYPE = 'English_United States.1252'
  11. CONNECTION LIMIT = -1;
  12.  
  13.  
  14. CREATE TABLE credits(
  15. cred_num int PRIMARY KEY,
  16. lect_hours int,
  17. lab_hours int,
  18. pract_hours int,
  19. ind_st_hours int,
  20. total_hours int
  21. );
  22.  
  23. CREATE TABLE subjects(
  24. subj_id int PRIMARY KEY,
  25. name varchar(20),
  26. cred_num int REFERENCES credits
  27. );
  28.  
  29. CREATE TABLE students(
  30. stud_id int PRIMARY KEY,
  31. fname varchar(20),
  32. lname varchar(20),
  33. bdate date,
  34. phnum int,
  35. email varchar(30),
  36. group_id int
  37. );
  38.  
  39. CREATE TABLE groups(
  40. group_id int PRIMARY KEY,
  41. name varchar(10),
  42. headstud_id int REFERENCES students(stud_id),
  43. major_id int
  44. );
  45.  
  46. ALTER TABLE students ADD FOREIGN KEY(group_id) REFERENCES groups(group_id);
  47.  
  48. CREATE TABLE ed_process(
  49. proc_id int PRIMARY KEY,
  50. group_id int REFERENCES groups,
  51. subj_id int REFERENCES subjects,
  52. term int
  53. );
  54.  
  55. CREATE TABLE progress(
  56. progress_id int PRIMARY KEY,
  57. proc_id int REFERENCES ed_process,
  58. stud_id int REFERENCES students,
  59. rk1 int,
  60. rk2 int,
  61. rk_avg int,
  62. exam int,
  63. final int
  64. );
  65.  
  66. CREATE TABLE teachers(
  67. teach_id int PRIMARY KEY,
  68. fname varchar(20),
  69. lname varchar(20),
  70. phnum int,
  71. email varchar(30),
  72. position varchar(30),
  73. dep_id int
  74. );
  75.  
  76. CREATE TABLE departments(
  77. dep_id int PRIMARY KEY,
  78. name varchar(50),
  79. room int,
  80. phnum int,
  81. email varchar(30),
  82. headteach_id int REFERENCES teachers(teach_id)
  83. );
  84.  
  85. ALTER TABLE teachers ADD FOREIGN KEY(dep_id) REFERENCES departments(dep_id);
  86.  
  87. CREATE TABLE majors(
  88. major_id int PRIMARY KEY,
  89. name varchar(100),
  90. dep_id int REFERENCES departments
  91. );
  92.  
  93. ALTER TABLE groups ADD FOREIGN KEY(major_id) REFERENCES majors(major_id);
  94.  
  95. CREATE TABLE classes(
  96. class_id int PRIMARY KEY,
  97. type varchar(15)
  98. );
  99.  
  100. CREATE TABLE schedule(
  101. sch_id int PRIMARY KEY,
  102. proc_id int REFERENCES ed_process,
  103. class_id int REFERENCES classes,
  104. teach_id int REFERENCES teachers,
  105. room int,
  106. time time,
  107. day_of_week varchar(5)
  108. );
  109.  
  110. INSERT INTO departments VALUES (1,'CSSE&T',409,124525,'caf.csse@gmail.com',NULL),
  111. (2,'IS',800,124525,'caf.is@gmail.com',NULL),
  112. (3,'EM',200,124525,'caf.em@gmail.com',NULL);
  113.  
  114. INSERT INTO majors VALUES (1,'CSSE',1),
  115. (2,'RET',1);
  116.  
  117. INSERT INTO groups VALUES (1,'CSSE-131',NULL, 1),
  118. (2,'CSSE-132',NULL, 1),
  119. (3,'CSSE-133',NULL, 1),
  120. (4,'CSSE-134',NULL, 1),
  121. (5,'CSSE-135',NULL, 1),
  122. (6,'CSSE-136',NULL, 1),
  123. (7,'CSSE-137',NULL, 1),
  124. (8,'CSSE-138',NULL, 1);
  125.  
  126. INSERT INTO students VALUES (1,'Shakhmardan','Abdiganiev','01/01/1995',1234567,'abdiganiev@gmail.com',1);
  127. INSERT INTO students VALUES (2,'Saulet','Abai','12/01/1995',1234567,'abai@gmail.com',2);
  128. INSERT INTO students VALUES (3,'Alina','Achilova','11/03/1995',1234567,'achilova@gmail.com',3);
  129. INSERT INTO students VALUES (4,'Tursyn','Adilkhan','12/10/1995',1234567,'adilkhan@gmail.com',4);
  130. INSERT INTO students VALUES (5,'Alisher','Asainov','12/10/1995',1234567,'asainov@gmail.com',5);
  131. INSERT INTO students VALUES (6,'Anuarkhan','Aimenov','03/24/1995',1234567,'aimenov@gmail.com',6);
  132. INSERT INTO students VALUES (7,'Almat','Akhat','03/25/1995',1234567,'akhat@gmail.com',7);
  133. INSERT INTO students VALUES (8,'Erkesh','Akkoshkarov','03/26/1995',1234567,'akkoshkarov@gmail.com',8);
  134.  
  135. INSERT INTO teachers VALUES (1,'Olga','Zvyaginceva',1234567,'zvyaginceva@gmail.com','Senior lecturer',1),
  136. (2,'Kairat','Sariyev',1234567,'sariyev@gmail.com','Senior lecturer',1),
  137. (3,'Nazgul','Rakhimzhanova',1234567,'rakhimzhanova@gmail.com','Senior lecturer',1),
  138. (4,'Lyudmila','Kozina',1234567,'kozina@gmail.com','Senior lecturer',1);
  139. INSERT INTO teachers VALUES (5,'Serik','Baibolat',1234567,'serik@gmail.com','Professor',1),
  140. (6,'Elaman','Kaipov',1234567,'kaipov@gmail.com','Senior lecturer',1),
  141. (7,'Nicole','Tesla',1234567,'Tesla@gmail.com','Professor',1),
  142. (8,'Rene','Descartes',1234567,'Descartes@gmail.com','Professor',1),
  143. (9,'Azamat','Maratovich',1234567,'Azicus@gmail.com','Senior lecturer',1),
  144. (10,'Almat','Meirbay',1234567,'Almat@gmail.com','Senior lecturer',1),
  145. (11,'Ersultan','Sayzin',1234567,'SZN@gmail.com','Professor',1);
  146.  
  147. INSERT INTO credits VALUES (1,15,15,0,15,45),
  148. (2,15,30,0,45,90),
  149. (3,15,30,15,60,120);
  150.  
  151. INSERT INTO subjects VALUES (1,'Database Design',2),
  152. (2,'Physics',3);
  153. INSERT INTO subjects VALUES(3, 'C++', 2),
  154. (4, 'Java', 3),
  155. (5, 'History', 1);
  156.  
  157. INSERT INTO ed_process VALUES (1,1,1,4),
  158. (2,2,1,4),
  159. (3,3,1,4),
  160. (4,4,1,4),
  161. (5,5,1,4),
  162. (6,6,1,4);
  163.  
  164. INSERT INTO ed_process VALUES(7,7,1,4),
  165. (8, 8, 1, 4),
  166. (9, 1, 2, 2),
  167. (10, 2, 2, 2),
  168. (11, 3, 3, 4),
  169. (12, 4, 2, 4),
  170. (13, 5, 4, 4),
  171. (14, 6, 4, 4),
  172. (15, 7, 2, 4),
  173. (16, 8, 2, 4);
  174.  
  175. INSERT INTO progress VALUES (1,1,1,90,90,90,90,90),
  176. (2,2,2,90,90,90,90,90),
  177. (3,2,3,90,90,90,90,90);
  178. INSERT INTO progress VALUES(4,4,4,80,80,80,90,90);
  179. INSERT INTO progress VALUES(5,5,4,60,90,75,90,90);
  180. INSERT INTO progress VALUES(6,5,6,50,100,75,90,90),
  181. (7,6,7,70,90,80,90,90),
  182. (8,7,8,40,90,65,80,90),
  183. (9,8,2,90,50,70,90,90),
  184. (10,9,3,60,60,60,90,90),
  185. (11,10,4,80,80,80,90,90),
  186. (12,11,8,70,70,70,90,90),
  187. (13,12,7,90,90,90,90,90);
  188.  
  189. INSERT INTO classes VALUES (1,'lecture'),
  190. (2,'lab'),
  191. (3,'pract');
  192.  
  193. INSERT INTO schedule VALUES (1,1,1,4,901,'10:00:00','mon'),
  194. (2,2,2,4,303,'08:00:00','mon');
  195. INSERT INTO schedule VALUES(3, 3, 2, 1, 700, '09:00:00', 'tue'),
  196. (4, 4, 1, 2, 800, '12:00:00', 'wed'),
  197. (5, 5, 3, 3, 701, '10:00:00', 'fri');
  198. INSERT INTO schedule VALUES(6, 6, 3, 5, 609, '09:00:00', 'mon'),
  199. (7, 7, 2, 6, 609, '09:00:00', 'thu'),
  200. (8, 8, 3, 7, 609, '09:00:00', 'mon'),
  201. (9, 9, 3, 8, 609, '09:00:00', 'mon'),
  202. (10, 10, 3, 9, 609, '09:00:00', 'sun');
  203. INSERT INTO schedule VALUES(11, 11, 1, 7, 901, '12:00:00', 'mon'),
  204. (12, 12, 1, 8, 907, '13:00:00', 'mon');
  205.  
  206. select g.name, sub.name, s.room, s.time, s.day_of_week, c.type, t.lname from Schedule s, Groups g, Subjects sub, Classes c, Teachers t, Ed_process ed
  207. where s.proc_id = ed.proc_id and ed.group_id = g.group_id and ed.subj_id = sub.subj_id and s.class_id = c.class_id and s.teach_id = t.teach_id;
  208.  
  209. select s.fname || ' ' || s.lname as FIO, sub.name, p.rk1, p.rk2, p.rk_avg, p.exam, p.final
  210. from Progress p, Ed_process ed, Subjects sub, Students s
  211. where p.proc_id = ed.proc_id and ed.group_id = s.group_id and ed.subj_id = sub.subj_id;
  212.  
  213. select g.name, sub.name, avg(p.final) from Ed_process ed, Groups g, Subjects sub, Progress p
  214. where ed.group_id = g.group_id and ed.subj_id = sub.subj_id group by g.name, sub.name;
  215.  
  216. select s.fname || ' ' || s.lname as FIO, avg(p.final) from Students s, Progress p
  217. where s.stud_id = p.stud_id group by s.fname, s.lname having avg(p.final) > 89 order by s.fname asc, s.lname asc;
  218.  
  219. select t.lname, sub.name, s.time, s.room from Schedule s, Subjects sub, Teachers t, Ed_Process ed
  220. where s.proc_id = ed.proc_id and s.teach_id = t.teach_id and ed.subj_id = sub.subj_id and s.class_id = 1 and s.day_of_week = 'mon';
  221.  
  222. select t.lname, count(*) as hours_in_a_week from Schedule s, Teachers t
  223. where s.teach_id = t.teach_id group by t.lname having count(*) > 0;
  224.  
  225. select g.name, ed.term, cd.total_hours from Groups g, Ed_process ed, Credits cd, Subjects sub
  226. where ed.group_id = g.group_id and ed.subj_id = sub.subj_id and sub.cred_num = cd.cred_num;
  227.  
  228. select s.fname || ' ' || s.lname as FIO, sub.name, p.rk1, p.rk2, p.rk_avg, p.exam, p.final
  229. from Progress p, Ed_process ed, Subjects sub, Students s
  230. where p.proc_id = ed.proc_id and ed.group_id = s.group_id and ed.subj_id = sub.subj_id and p.final between 80 and 95;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement