use Myschool
--查询GradeId为1的
SELECT * FROM Student WHERE GradeId=1
--查询学生姓名和年级名称
SELECT Student.StudentName,Grade.GradeNema FROM Student,Grade WHERE Student.GradeId=Grade.GradeId
--查询年级名称为Y2的
SELECT Student.StudentName,Grade.GradeNema FROM Student,Grade WHERE GradeNema='y2' AND Student .GradeId=Grade.GradeId
--查询学生编号和所考科目名称
SELECT Result.StudentNo,Subject.SubjectName FROM Result,Subject WHERE Result.Subjectld=Subject.Subjectld
--AS
--AS放入列时,代替列名
SELECT Result.StudentNo AS 学生编号,Subject.SubjectName AS 科目名称
FROM Result,Subject WHERE Result.Subjectld=Subject.Subjectld
--AS放入表时,代替表名
SELECT r.StudentNo,s.SubjectName
FROM Result AS r,Subject AS s WHERE r.Subjectld=s.Subjectld
--使用+拼接列名
SELECT StudentName+'----'+Sex AS '姓名性别' FROM Student
--查询空值得列
SELECT *FROM Student WHERE Email IS NULL
--常量列
SELECT StudentName AS '学生姓名','10010' AS '编码' FROM Student
--查询固定行数
SELECT TOP 5* FROM Student
--查询百分比固定行数
SELECT TOP 20 PERCENT * FROM Student
--数据排序:降序排列(desc)生序排列(asc):默认的
SELECT * FROM Result ORDER BY StudentResult DESC,ExamDate ASC