例说SQLServer2008聚合函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 CREATE TABLE tb_Class( classid int NOT NULL IDENTITY, classname NVARCHAR(16) NOT NULL, students int NOT NULL, teacher NVARCHAR(16) NOT NULL, PRIMARY KEY(classid)) INSERT INTO tb_Class(classname,students,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE tb_Class(
classid int NOT NULL IDENTITY,
classname NVARCHAR(16) NOT NULL,
students int NOT NULL,
teacher NVARCHAR(16) NOT NULL,
PRIMARY KEY(classid))
INSERT INTO tb_Class(classname,students,teacher)
VALUES
('1班',25,'yl'),('2班',18,'wsp'),('3班',24,'yl'),('4班',25,'zhy'),
('5班',22,'wsp'),('6班',25,'yl'),('7班',20,'zhy'), ('8班',22,'wsp')
SELECT SUM(students) FROM tb_Class GROUP BY teacher
SELECT COUNT(students) FROM tb_Class GROUP BY teacher
SELECT AVG(students) FROM tb_Class GROUP BY teacher
SELECT MAX(students) FROM tb_Class GROUP BY teacher
SELECT MIN(students) FROM tb_Class GROUP BY teacher
,