SQL聚合函数
-
MAX---最大值
-
MIN--最小值
-
AVG--平均值
-
SUM--求和
-
COUNT--记录的条数
EXample:
--从MyStudent表中查询最大年龄,最小年龄,平均年龄,年龄的总和
--SELECT MAX(S_Age) AS MaxAge ,MIN(S_Age) AS MinAge,AVG(S_Age) AS AVGAGE ,SUM(S_Age) AS SUMAGE FROM dbo.MyStudent
扩展
--效率比较低,先从系统表中,查询该表有哪些列,然后再查询。一般不用;
SELECT * FROM dbo.MyStudent
--这个效率高一点,明确指定了哪些列
SELECT S_ID, S_Name, S_Gender, S_Address, S_Phone, S_Age, S_Birthday, S_CardID, S_CID FROM dbo.MyStudent
聚合函数对NULL值不计算
SELECT * FROM dbo.Customers
SELECT COUNT(CustomerID) FROM dbo.Customers
SELECT COUNT(Region) FROM dbo.Customers
这三句代码,得到的结果是: