当前位置:Gxlcms > 数据库问题 > Oracle_多行函数

Oracle_多行函数

时间:2021-07-01 10:21:17 帮助过:20人阅读

 

技术分享

多行函数min(),max(),count(),sum(),avg()
--1.1统计公司的最高工资,最低工资和总人数 --对于null值直接略过,不做运算 --max,min,count可以对任意类型进行操作 select max(sal), min(sal),count(empno) from emp; select max(sal), min(sal),count(comm) from emp; select max(sal), min(sal),count(mgr) from emp;   select sum(comm), avg(comm) from emp;   select max(ename), min(hiredate) from emp;  
--2.统计emp表中的记录数 select count(*) from emp;   --2.1统计部门编号为10的部门员工总数  select count(*) from emp where deptno=10;  
--3.分组group by,    order by永远放在最后 --统计每个部门的部门编号,员工人数,并按照部门编号进行排序 select deptno, count(*) from emp group by deptno order by deptno;   --3.1查询各个部门的编号,人数,总工资,平均工资,最高工资,最低工资 select  deptno, count(*), sum(sal), avg(sal), max(sal), min(sal) from emp group by deptno order by avg (sal); select count(*), sum(sal), avg(sal), max(sal), min(sal) from emp group by deptno order by avg (sal);   --3.2统计每个部门的人数,排除编号为30的部门 --先写where子句,后写group by select deptno, count(*) from emp where deptno<>30 group by deptno;  
-4.统计每个部门的平均工资,排除平均工资小于2000的部门 --where子句中不允许使用多行函数 --having分组完成后,进行筛选(不能使用别名进行判断),having的语法和where基本一致 select deptno, avg(sal) from emp group by deptno having avg(sal)>=2000; select deptno, avg(sal) from emp group by deptno having avg(sal)>=2000 and deptno<>10;  
练习
--在emp表中,列出工资最小值小于2000的职位 select job,min(sal) from emp group by job having min(sal)<2000;     --列出平均工资大于1200的部门和工作搭配的组合 select deptno,job,avg(sal) from emp group by deptno,job having avg(sal)>1200;  

--统计人数小于4的部门的平均工资 select deptno,avg(sal),count(*) from emp group by deptno having count(*)<4;     --统计各部门的最高工资,排除最高工资小于3000的部门 select from emp group by deptno having max(sal)>3000;  



 

Oracle_多行函数

标签:3.1   允许   group   window   公司   where   http   使用   eee   

人气教程排行