Part1:
分组函数的介绍
1、sum();
2、avg();以上参数只能是数值型,忽略null值
3、min()
4、max();
5、count();以上参数可以是任何类型,count 忽略null值
select sum(salary) 和,round(avg(salary),2) 均值,min(salary) 最小 from employees;
回顾:round(avg(salary),2) 对数保留两位小数
6、以上函数都可以与distinct 函数结合
select count(distinct salary) from employees;
7、select count () from employees; #统计行数,效率高
select count (1) from employees; #统计行数,效率高,count(字段)效率最差
8、查询的字段要同步长度
datediff(now(),‘1990-1-1’)
9、查询时间差
select datediff(now(),‘1900-1-1’);
10、查询部门编号 为90的员工个数
select ()from employees where department_id=90;
11、查询每个工种的最高工资
select max(salary),job_id
from employees
groub by job_id;
12、查询每个位置上的部门个数
select count(*),location_id
from employees
group by location_id;
13、查询邮箱含有字母a的,每个部门的名称和平均工资
select avg(salary),department_id
from employees
where email like ‘%a%’
group by department_id
group by 要在where之后
14、having关键字的使用
select count(),department_id
from employees
#此处用where count()>2会报错
group by department_id
having count(*)>2
来源:CSDN
作者:我就要学C++
链接:https://blog.csdn.net/qq_33069557/article/details/104001990