分组查询
--根据员工所在地区分组,统计员工人数,工资总和,平均工资,最高工资,最低工资
--方案1
select '武汉' 地区,count(*) 员工人数,sum(PeopleSalary) 工资总和,
avg(PeopleSalary) 平均工资,max(PeopleSalary) 最高工资,
min(PeopleSalary) 最低工资
from People where PeopleAddr='武汉'
union
select '北京' 地区,count(*) 员工人数,sum(PeopleSalary) 工资总和,
avg(PeopleSalary) 平均工资,max(PeopleSalary) 最高工资,
min(PeopleSalary) 最低工资
from People where PeopleAddr='北京'
--方案2
select PeopleAddr 地区,count(*) 员工人数,sum(PeopleSalary) 工资总和,
avg(PeopleSalary) 平均工资,max(PeopleSalary) 最高工资,
min(PeopleSalary) 最低工资
from People group by PeopleAddr
--根据员工所在地区分组,统计员工人数,工资总和,平均工资,最高工资,最低工资
--1985年以后的不参与统计
select PeopleAddr 地区,count(*) 员工人数,sum(PeopleSalary) 工资总和,
avg(PeopleSalary) 平均工资,max(PeopleSalary) 最高工资,
min(PeopleSalary) 最低工资
from People where PeopleBirth < '1985-1-1'
group by PeopleAddr
--根据员工所在地区分组,统计员工人数,工资总和,平均工资,最高工资,最低工资
--要求筛选出地区员工数是2人及以上的记录,1985年以后的不参与统计
select PeopleAddr 地区,count(*) 员工人数,sum(PeopleSalary) 工资总和,
avg(PeopleSalary) 平均工资,max(PeopleSalary) 最高工资,
min(PeopleSalary) 最低工资
from People where PeopleBirth < '1985-1-1'
group by PeopleAddr having count(*) >= 2
标签:PeopleSalary,--,工资,08,最低工资,查询,分组,员工,PeopleAddr
From: https://www.cnblogs.com/Starry-blog/p/16797311.html