sql server 聚合函数

--聚合函数
--count :求数量
--max  : 求最大值
--min : 求最小值
--sum :求和
--avg :求平均值
select count(*) 数量 from People
select Max(PeopleSalary) 最高工资 from People
select min(PeopleSalary) 最低工资 from People
select sum(PeopleSalary) 工资总和 from People
--求所有员工的平均工资
select avg(PeopleSalary) 平均工资 from People
select round(25.5555,2)

select count(*)人数 ,max(PeopleSalary)最高工资 ,min(PeopleSalary)最低工资,sum(PeopleSalary)工资之和,avg(PeopleSalary) 平均工资 from People 

select count(*) 人数  ,max(PeopleSalary) from People where PeopleAddress='中国'

--求出工资比平均工资高的人员
select * from People where PeopleSalary>(select round(avg(PeopleSalary),2)平均工资 from People)

--求数量,年龄最大值,年龄最小值,年龄总和,年龄平均值,在一行显示
select *,year(getdate())-year(PeopleBirth) 年龄 from People
select count(*) 数量,
max(year(getdate())-year(PeopleBirth)) 最高年龄,
min(year(getdate())-year(PeopleBirth)) 最低年龄,
sum(year(getdate())-year(PeopleBirth)) 年龄总和,
avg(year(getdate())-year(PeopleBirth)) 平均年龄
from People 
select count(*) 数量,
max(datediff(year,PeopleBirth,getdate())) 最高年龄,
min(datediff(year,PeopleBirth,getdate())) 最低年龄,
sum(datediff(year,PeopleBirth,getdate())) 年龄总和,
avg(datediff(year,PeopleBirth,getdate())) 平均年龄
from People 
select count(*) 数量,
max(year(getdate())-year(PeopleBirth)) 最高年龄,
min(year(getdate())-year(PeopleBirth)) 最低年龄,
sum(year(getdate())-year(PeopleBirth)) 年龄总和,
avg(year(getdate())-year(PeopleBirth)) 平均年龄
from People where PeopleSex='男'and PeopleAddress='北京'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_53944811

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值