时间:2021-07-01 10:21:17 帮助过:31人阅读
select comm from emp;--查询工资最高的员工select ename,job,sal from emp where sal = (select max(sal) from emp);select ena
select comm from emp;
--查询工资最高的员工
select ename,job,sal from emp where sal = (select max(sal) from emp);
select ename,job,sal*13+nvl(comm,0)*13 s from emp order by s desc;
--查询平均工资,总工资
select avg(nvl(sal,0)),sum(nvl(sal,0)) from emp;
--查询奖金
select avg(comm),sum(comm) from emp;
--group by 和having
select avg(sal),sum(sal),deptno from emp group by deptno;
select count(comm) from emp ;
select count(ename) from emp ;
----显示每个部门的每种岗位的平均工资和最高工资
select avg(sal),sum(sal),deptno,job from emp group by deptno, job
----显示部门平均工资低于2000的部门和他的平均工资
--思路1:查询出每个部门的平均工资
select avg(sal),deptno from emp GROUP by deptno;
--思路2:挑出低于2000的部门
select avg(sal),deptno from emp GROUP by deptno HAVING AVG(sal)<5000;
----1,分组函数(avg(),sum().....)只能出现在选择列表,having,order by 子句中
----2,如果在select语句中同时包含有group by ,having,order by 那么它们的顺序是group by ,having,,order by
----3,在选择列中如果有列,表达式,和分组函数,那么这些列和表达式必须有一个出现在group by 子句中