sqlserver 模糊查询,连表,聚合函数,分组

Posted spinoza

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver 模糊查询,连表,聚合函数,分组相关的知识,希望对你有一定的参考价值。

 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,StudentAddress,age from Students
16 where Age in(21,22,23)
17 
18 select StudentName,StudentAddress,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,StudentName,Gender ,C#成绩=CSharp from Students
35 left outer join ScoreList on Students.StudentId=ScoreList.StudentId
36 where Gender=
37 
38 select  Students.StudentId,StudentName,Gender ,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

 

以上是关于sqlserver 模糊查询,连表,聚合函数,分组的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver_query3_去重查询|模糊查询|排序|分组|使用函数

18 12 06 sql 的 基本语句 查询 条件查询 逻辑运算符 模糊查询 范围查询 排序 聚合函数 分组 分页 连接查询 自关联 子查询

Oracle数据库,模糊查询去重查询

SqlServer:分组查询和聚集函数

数据库查询

窗口聚合函数与分组聚合函数的异同