user E_book
go
select sum(user),play from 表名 where name= 这样的程序会出错,因为play没有使用sum,所以要分组。
select sum(user),play 表名 where name= group by play
有函数的和没有函数的表一起使用要用 GROUP BY
.AVG 求平均值,只能与数值型一起使用 空值被忽略。
select avg(fitem) from 表名 where name=
.MAX和MIN,求最大最小值,空值被忽略 可以和数值、日期、字符一起使用
select MAX(nianling) as 年龄 from 表名
.count 用于统计记录中的记录数,如果写列名空值被忽略。
select count(*) from user 统计所有记录数
select count (name) from user 统计用户数
例如使用语句count函数来获取employee表中的员工数量。
use book --指定数据库
GO
select count(employID) from employee
GO
又如,下面的语句使用sum函数计算sales表中的销售总额
USE book
GO
select sum(linetotal)from sales
GO