1 use StudentManageDB 2 go 3 select StudentName,StudentAddress from Students 4 where StudentAddress like ‘天津%‘ 5 6 select StudentName,StudentAddress from Students 7 where StudentName like ‘%小%‘ 8 9 select * from scoreList 10 where CSharp between 80 and 90 11 12 select StudentName,StudentAddress,Birthday from Students 13 where Birthday between ‘1987-01-01‘ and ‘1988-01-01‘ 14 15 select StudentName,age from Students 16 where Age in(21,22,23) 17 18 select StudentName,age from Students 19 where StudentName in(‘王小虎‘,‘贺小张‘) 20 21 22 select SUM(CSharp) as C#总成绩 from scoreList 23 24 select 总人数=COUNT(*) from Students 25 26 select MAX(Csharp) as C#最高分,MIN(CSharp) as C#最低分,AVG(CSharp) as C#最低分 from scoreList 27 28 select Students.StudentId,C#成绩=CSharp,StudentName,ClassName 29 from scoreList 30 inner join Students on Students.StudentId=scoreList.StudentId 31 inner join StudentClass on Students.ClassId=StudentClass.ClassId 32 where CSharp >80 33 34 select Students.StudentId,Gender,C#成绩=CSharp from Students 35 left outer join scoreList on Students.StudentId=scoreList.StudentId 36 where Gender=‘男‘ 37 38 select Students.StudentId,C#成绩=CSharp from scoreList 39 left outer join Students on Students.StudentId=scoreList.StudentId 40 where Gender=‘男‘ 41 42 select 班级=StudentClass.ClassName,人数=COUNT(*),C#最高分=Max(CSharp),DB最高分=MAX(sqlServerDB),43 AVG(CSharp) as C#平均分,AVG(sqlServerDB) as DB平均分 44 from Students 45 inner Join StudentClass on Students.ClassId =StudentClass.ClassId 46 inner join scoreList on scoreList.StudentId=Students.StudentId 47 group by ClassName 48 having AVG(CSharp)>=70 and AVG(sqlServerDB)>=70 49 50 select * from scoreList 51 select StudentId from scoreList group by StudentId having COUNT(*)>1 52 53 select * from scoreList 54 where StudentId in(select StudentId from scoreList group by StudentId having COUNT(*)>1) 55 order by StudentId 56 57 select * from scoreList 58 where (select COUNT(*) from scoreList s where s.StudentId=scoreList.StudentId)>1 59 order by StudentId