realsdx

DBMS LAB 4

Feb 28th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. 1.mysql> select name from instructor where dept_name='Comp. Sci.';
  2. +------------+
  3. | name |
  4. +------------+
  5. | Srinivasan |
  6. | Katz |
  7. | Brandt |
  8. +------------+
  9. 3 rows in set (0.03 sec)
  10.  
  11. 2.mysql> select course_id,title from course where course.dept_name in(select dept_name from instructor where name='Srinivasan');
  12. +-----------+----------------------------+
  13. | course_id | title |
  14. +-----------+----------------------------+
  15. | CS-101 | Intro. to Computer Science |
  16. | CS-190 | Game Design |
  17. | CS-315 | Robotics |
  18. | CS-319 | Image Processing |
  19. | CS-347 | Database System Concepts |
  20. +-----------+----------------------------+
  21. 5 rows in set (0.04 sec)
  22.  
  23.  
  24. 3.mysql> select ID,name from instructor where dept_name='Comp. Sci.';
  25. +-------+------------+
  26. | ID | name |
  27. +-------+------------+
  28. | 10101 | Srinivasan |
  29. | 45565 | Katz |
  30. | 83821 | Brandt |
  31. +-------+------------+
  32. 3 rows in set (0.00 sec)
  33.  
  34.  
  35. 4.mysql> select name from instructor where instructor.ID in(select ID from teaches where semester='Spring' and year='2009');
  36. +--------+
  37. | name |
  38. +--------+
  39. | Brandt |
  40. | Kim |
  41. +--------+
  42. 2 rows in set (0.00 sec)
  43.  
  44.  
  45. 5.mysql> select SUM(capacity) from classroom where building='Watson';
  46. +---------------+
  47. | SUM(capacity) |
  48. +---------------+
  49. | 80 |
  50. +---------------+
  51. 1 row in set (0.00 sec)
  52.  
  53. 6.mysql> select name from student where student.dept_name in(select dept_name from instructor where name='Singh');
  54. +--------+
  55. | name |
  56. +--------+
  57. | Chavez |
  58. +--------+
  59. 1 row in set (0.01 sec)
  60.  
  61.  
  62. 7.mysql> select title from course where course.course_id in(select course_id from teaches where semester='Spring' and year='2010');
  63. +----------------------------+
  64. | title |
  65. +----------------------------+
  66. | Intro. to Computer Science |
  67. | Robotics |
  68. | Image Processing |
  69. | Investment Banking |
  70. | World History |
  71. | Music Video Production |
  72. +----------------------------+
  73. 6 rows in set (0.00 sec)
  74.  
  75.  
  76. 8.mysql> select ID,name from instructor where salary in(select MAX(salary) from instructor);
  77. +-------+----------+
  78. | ID | name |
  79. +-------+----------+
  80. | 22222 | Einstein |
  81. +-------+----------+
  82. 1 row in set (0.00 sec)
  83.  
  84.  
  85. 9.mysql> select * from classroom where room_number in(select room_number from section where course_id in(select course_id from course where title='Robotics'));
  86. +----------+-------------+----------+
  87. | building | room_number | capacity |
  88. +----------+-------------+----------+
  89. | Watson | 120 | 50 |
  90. +----------+-------------+----------+
  91. 1 row in set (0.02 sec)
  92.  
  93.  
  94. 10.mysql> select ID,name from instructor where ID in(select ID from teaches where course_id in(select course_id from course where title='Database System Concepts'));
  95. +-------+------------+
  96. | ID | name |
  97. +-------+------------+
  98. | 10101 | Srinivasan |
  99. +-------+------------+
  100. 1 row in set (0.00 sec)
  101.  
  102. 11. mysql> select dept_name, count(ID) as Number from instructor group by dept_name order by Number desc;
  103. +------------+--------+
  104. | dept_name | Number |
  105. +------------+--------+
  106. | Comp. Sci. | 3 |
  107. | Finance | 2 |
  108. | History | 2 |
  109. | Physics | 2 |
  110. | Music | 1 |
  111. | Biology | 1 |
  112. | Elec. Eng. | 1 |
  113. +------------+--------+
  114. 7 rows in set (0.00 sec)
  115.  
  116. 12. mysql> select dept_name, AVG(salary) from instructor group by dept_name;
  117. +------------+--------------+
  118. | dept_name | AVG(salary) |
  119. +------------+--------------+
  120. | Biology | 72000.000000 |
  121. | Comp. Sci. | 77333.333333 |
  122. | Elec. Eng. | 80000.000000 |
  123. | Finance | 85000.000000 |
  124. | History | 61000.000000 |
  125. | Music | 40000.000000 |
  126. | Physics | 91000.000000 |
  127. +------------+--------------+
  128. 7 rows in set (0.00 sec)
  129.  
  130. 13. mysql> select dept_name, AVG(salary) as avg_salary from instructor group by dept_name having avg_salary > 42000;
  131. +------------+--------------+
  132. | dept_name | avg_salary |
  133. +------------+--------------+
  134. | Biology | 72000.000000 |
  135. | Comp. Sci. | 77333.333333 |
  136. | Elec. Eng. | 80000.000000 |
  137. | Finance | 85000.000000 |
  138. | History | 61000.000000 |
  139. | Physics | 91000.000000 |
  140. +------------+--------------+
  141. 6 rows in set (0.00 sec)
  142.  
  143. 14. mysql> select title from course where course.course_id in (select course_id from teaches where (semester="Fall" and year="2009") OR (semester="Spring" and year="2010"));
  144. +----------------------------+
  145. | title |
  146. +----------------------------+
  147. | Intro. to Computer Science |
  148. | Robotics |
  149. | Image Processing |
  150. | Database System Concepts |
  151. | Investment Banking |
  152. | World History |
  153. | Music Video Production |
  154. | Physical Principles |
  155. +----------------------------+
  156. 8 rows in set (0.01 sec)
  157.  
  158. 15. mysql> select title from course where course.course_id in (select course_id from teaches where (semester="Fall" and year="2009") OR (semester!="Spring" and year!="2010"));
  159. +----------------------------+
  160. | title |
  161. +----------------------------+
  162. | Intro. to Biology |
  163. | Intro. to Computer Science |
  164. | Database System Concepts |
  165. | Physical Principles |
  166. +----------------------------+
  167. 4 rows in set (0.00 sec)
  168.  
  169.  
  170.  
  171. 16. mysql> select name from instructor where salary > (select MAX(salary) from instructor where dept_name="Biology");+----------+
  172. | name |
  173. +----------+
  174. | Wu |
  175. | Einstein |
  176. | Gold |
  177. | Katz |
  178. | Singh |
  179. | Brandt |
  180. | Kim |
  181. +----------+
  182. 7 rows in set (0.02 sec)
  183.  
  184. 17. mysql> select dept_name , avg_salary from (select dept_name, AVG(salary) as avg_salary from instructor group by dept_name having avg_salary > 42000) as T;
  185. +------------+--------------+
  186. | dept_name | avg_salary |
  187. +------------+--------------+
  188. | Biology | 72000.000000 |
  189. | Comp. Sci. | 77333.333333 |
  190. | Elec. Eng. | 80000.000000 |
  191. | Finance | 85000.000000 |
  192. | History | 61000.000000 |
  193. | Physics | 91000.000000 |
  194. +------------+--------------+
  195. 6 rows in set (0.03 sec)
  196.  
  197. 18. mysql> update instructor set salary= case when salary>80000 then salary*1.03 else salary*1.05 end;
  198. Query OK, 12 rows affected (0.40 sec)
  199. Rows matched: 12 Changed: 12 Warnings: 0
Add Comment
Please, Sign In to add comment