首页 > 代码库 > 优化Myschool数据库设计联合、联接、子查询

优化Myschool数据库设计联合、联接、子查询

USE MySchool
go


--联合查询:合并多个数据集中的行
SELECT StudentNo,SubjectNo,StudentResult From Result
--UNION
SELECT SubjectNo,ClassHour,GradeID From Subject

--联接查询:合并多个数据集中的列
SELECT StudentName AS 姓名,SubjectNo AS 课程编号,StudentResult AS 成绩
FROM Student INNER JOIN Result ON Student.StudentNo = Result.StudentNo

--子查询:偏重于筛选符合条件的记录
SELECT * FROM Student WHERE GradeId =
(SELECT GradeId FROM Grade WHERE GradeName = ‘S1‘)

优化Myschool数据库设计联合、联接、子查询