AVG() 函數返回數字列的平均值
注意是數字的平均數,
語法:
select avg(字段) from 表名
建個表,弄點數據
使用
select avg(字段) as 平均數 from 表名
與where 字句一塊使用
與count () 函數
sum() 求和函數 返回數字列的總和
語法:
select sum(字段) as 總和 from 表名
與avg 函數一塊使用
熟悉之后可以按照想法組合
代碼:
-- -- avg() 與 sum 函數 select avg(Gongzi) as 工資平均數 from obgetest -- 與where 字句一塊進行使用 select * from obgetest where Gongzi>(select AVG(Gongzi) from obgetest) -- 與count 函數 -- 查詢工資大於平均工資中工資數目不同的行數 select COUNT(DISTINCT Gongzi) as 工資行數 from obgetest where Gongzi>(select AVG(Gongzi)from obgetest) -- sum() 求和函數 -- 求出表中工資大於平均工資的總和 select SUM(Gongzi)as 工資總數 from obgetest where Gongzi>(select AVG(Gongzi)from obgetest)