–任务1 : 査询选修某课程的学生倍息
–查询选修课程编号为"0101001"课程的学生的学号和姓名
–方法一:连接查询(内连接),分析数据源(单表、多表)
SELECT *
FROM Student,Result WHERE Student.Sno=Result.sno
SELECT *
FROM Student INNER JOIN Result
ON Student .Sno=Result.sno
–方法二:IN子查询,从已知条件(课程编号0101001)去查询有关学生的信息
–适合内部表(子表)记录较少的情况
SELECT *
FROM Result
WHERE cno='0101001'
SELECT *
FROM Student
WHERE Sno IN ('1201011101','1201011102','1201011103')
SELECT *
FROM Student
WHERE Sno IN(
SELECT Sno
FROM Result
WHERE cno='0101001')
--EXISTS子查询,适合外部表(父表)记录较少的情况
SELECT *
FROM Student
WHERE EXISTS(
SELECT *
FROM Result
WHERE cno='0101001' AND Student.Sno=Result.Sno )