8-1
mysql> select * from instructor where dept_name="Biology";
+-------+-------+-----------+----------+
| ID | name | dept_name | salary |
+-------+-------+-----------+----------+
| 76766 | Crick | Biology | 72000.00 |
+-------+-------+-----------+----------+
1 row in set (0.06 sec)
8-2
mysql> select * from course where dept_name="Comp. Sci." and credits="3"
-> ;
+-----------+--------------------------+------------+---------+
| course_id | title | dept_name | credits |
+-----------+--------------------------+------------+---------+
| CS-315 | Robotics | Comp. Sci. | 3 |
| CS-319 | Image Processing | Comp. Sci. | 3 |
| CS-347 | Database System Concepts | Comp. Sci. | 3 |
+-----------+--------------------------+------------+---------+
3 rows in set (0.05 sec)
8-3
select course_id, title from course where course_id in (select course_id from takes where ID="12345");
或
select course.course_id, course.title from course natural join takes where ID="12345";
8-4
select sum(credits) from course natural join takes where ID="12345";
8-5
select id,sum(credits) from course natural join takes group by id;