Oracle查询语句

来源:互联网 发布:淘宝钻石展位展现位置 编辑:程序博客网 时间:2024/06/03 22:54

一.简单表查询

1.查看emp表中所有数据

select  *  from emp;

2.查询雇员的员工编号和姓名

select empno,ename from emp;

3.查询当前的系统时间

select sysdate from dual;

4.查询薪水高于3000的员工信息

select * from emp where sal>=3000;

5.查询薪水不等于3000的员工信息

select * from emp where sal!=3000;

6.查询薪水等于3000,或等于1250的员工信息

select * from emp where sal=any(3000,1250);

7.查询薪水不等于3000,并且不等于1250的员工信息

select * from emp where sal!=all(3000,1250);

8.查询出emp表中每个员工姓名和年薪(不计算奖金

select ename,sal*12 from emp;

9.查询出emp表中每个员工姓名和年薪(计算奖金)

select ename,12*(sal+nvl(comm,0)) from emp;

10.查询出工资高于3000或者岗位为manager的员工信息

select  *  from emp where sal>3000 or job='MANAGER';

11.查询出岗位为manager的且在10号部门的员工信息

select  * from emp where job='MANAGER' and deptno=10;

12.找出部门10中所有经理和部门20中所有办事员以及既不是经理又不是办事员但其薪金大于或等于2000

select * from emp where(deptno=10 and job='MANAGER') or(deptno=20 and job='CLERK') or (job !=all('MANAGER','CLERK')and sal>=2000);

13.emp表工资在2000-3800之间

select * from emp where sal between 2000 and 3800;

14.查询出姓名第二个字母为A的员工信息

select * from emp where ename like '_A%';

15.职工名字第一个是S的

select * from emp where ename like 'S%';

16.职工最后一个字母是H的

select * from emp where ename like '%H';

17.显示empno为7844,7839,123,456的雇员情况

select * from emp where empno=any(7844,7839,123,456);

select * from emp where empno in(7844,7839,123,456);

18.查找没有上级的雇员

select * from emp where mgr is null;

查询排序

1.查询出emp表中所有员工信息,按照工资顺序从低到高显示

select * from emp order by sal asc;

2.查询出emp表中所有员工信息,按照工资顺序从高到底显示

select * from emp order by desc;

3.查询出emp表中多有员工的姓名和年薪(包括奖金),按照年薪从高到低排序

select ename,12*(sal+nvl(comm,0)) 年薪 from emp order by 年薪 desc;

4.查询出emp表中所有员工信息,按照部门从低到高排序,再在部门内按照工资从低到高排序

select *  from emp order by deptno,sal;

5.查询出emp表中所有员工信息,按照部门从低到高排序,再在部门内按照工资从高到低排序

select * from emp order by deptno,sal desc;

6.查询出emp表中最高工资的员工姓名,工资

select ename,sal from emp where sal =(select max(sal) from emp);

7.查询出emp表中高于平均工资的员工信息

select * from emp where sal>(select avg(sal) from emp);

8.查询出公司一年的薪水支出(加上奖金)

select sum(12*(sal+nvl(comm,0))) 薪水支出 from emp;

9.查询部门编号为30的部门有多少员工

select count(*) from emp where deptno=30;

10.查询emp表中的数据条数

select count(*) from emp;

11.查询出每个部门的最高工资

select deptno,max(sal) from emp group by deptno;

12.查询出每个部门的最高工资,最低工资,平均工资

select deptno,max(sal),min(sal),avg(sal) from emp group by deptno;

13.查询出平均工资高于2000的部门

select deptno,avg(sal) from emp group by deptno having avg(sal)>2000;

原创粉丝点击