(有些有两个答案看不懂的话在用户Scott下运行一下结合输出的结果一起看)
01.查询每个雇员的编号、姓名、职位。
select empno,ename,job from emp;
02.查询每个雇员的职位,职位。
select ename,job from emp;
03.查询每个雇员的职位,使用DISTINCT消除掉显示的重复行记录。
select distinct job from emp;
04.计算出每个雇员的基本年薪,同时查询出雇员的编号、姓名。
select (sal+nvl(comm,0))*12,empno,ename from emp;
05.每个雇员每个月公司会补贴饭食200元,交通补助300元,计算年薪(年薪=(工资+奖金)*12)。select (sal+nvl(comm,0)+500)*12 from emp;
06.查询基本工资高于2000的全部雇员信息。select * from emp where sal>2000;
07.查询出smith的信息。select * from emp where ename='SMITH';08.查询出所有不是CLERK的详细信息。
select * from emp where not job = 'CLERK';
09.查询出所有销售人员(SALESMAN)的基本信息,并且要求销售人员的工资高于1300。
select * from emp where job='SALESMAN' and sal>'1300';
10.查询出工资范围在1500~3000之间的全部雇员信息(包含1500和3000)。
select * from emp where sal between 1500 and 3000;
11.查询出所有经理或者是销售人员的信息,并且要求这些人的基本工资高于1500。
select * from emp where not job in('MANAGER','SALESMAN') and sal>1500;
12.要求查询出所有在1981年雇佣的雇员信息。select * from emp where to_char(hiredate,'yyyy')=1981;
13.查询所有领取奖金的雇员信息(comm不为空)。
select * from emp where not comm is null;
14.查询所有领取奖金高于100的雇员信息。
select * from emp where comm>100;
15.查询出雇员编号是7369、7566、9999的雇员信息。
select * from emp where empno in(7369,7566,9999);
16.查询出所有雇员姓名是以A开头的全部雇员信息。
select * from emp where ename like 'A%';
17.查询出雇员姓名第二个字母是M的全部雇员信息。
select * from emp where ename like '_M%';
18.查询出雇员姓名任意位置上包含字母A的全部雇员信息。
select * from emp where ename like '%A%';
19.查询出所有雇员的信息,要求按照工资排序。select * from emp order by sal;
20.要求查询所有雇员的信息,按照雇佣日期由先后排序。
select * from emp order by hiredate;
21.查询全部雇员信息,按照工资由高到低排序,如果工资相同,则按照雇佣日期由先后排序。
select * from emp order by sal desc,hiredate;
22.查询部门30中的所有员工。
select * from emp where deptno=30;
23.查询出所有办事员(CLERK)的姓名,编号和部门编号。
select empno,deptno from emp where job='CLERK';
24.查询出奖金高于薪金的员工。
select * from emp where sal<comm;
25.查询出奖金高于薪金的60%的员工。
select * from emp where sal*0.6<comm;
26.查询出部门10中所有经理(MANAGER)和部门20中所有办事员(CLERK)的详细资料。
select * from emp where deptno=10 and job='MANAGER' or deptno=20 and job='CLERK';
27.查询出部门10中所有经理,部门20中所有办事员,既不是经理又不是办事员但其薪金大于或等于2000的所有员工的信息。
select * from emp where (deptno=20 and job='CLERK' or deptno=10 and job='MANAGER') or (job not in('CLERK','MANAGER') and sal>2000);
28.查询出收取奖金的员工的不同工作。
select distinct job from emp where not comm is null;
29.查询出不收取奖金或收取的奖金低于100的员工。
select * from emp where comm<100;
30.查询出不带有“R”的员工的姓名。
select * from emp where not ename like'%R%';
31.查询出每个雇员的姓名、职位、领导姓名。select e.ename,e.job,(select ename from emp where e.mgr=empno) 领导名字 from emp e;select e.ename,e.job,q.ename from emp e left join emp q on e.mgr=q.empno;
32.查询出所有员工的编号、姓名及其直接上级的编号、姓名,显示的结果按领导年工资的降序排列。
select e.empno,e.ename,q.empno,q.ename from emp e,emp q where e.mgr=q.empno order by q.sal;
33.查询出在销售部(SALES)工作的员工姓名、基本工资、雇佣日期、部门名称。(不知道销售部编号)。
select e.ename,e.sal,e.hiredate,d.dname from emp e,dept d where e.deptno=d.deptno and d.dname='SALES';
35.查询出所有员工的年工资,所在部门名称,按年薪从低到高排序。
select (e.sal+nvl(comm,0))*12,d.dname from emp e,dept d where e.deptno=d.deptno order by (e.sal+nvl(comm,0))*12;
36.查询出某个员工的上级主管及所在部门名称,并要求出这些主管中的薪水超过3000。select distinct e.ename,n.empno,d.dname from emp e,(select q.empno,q.sal,q.deptno from emp e left join emp q on e.mgr=q.empno) n,dept d where n.deptno=d.deptno and e.deptno=d.deptno and e.deptno=n.deptno and n.sal>3000;
select dname,ename from emp e,emp q,dept d where e.mgr=q.empno and q.deptno=d.deptno and q.sal>3000;
37.查询出公司的最高和最低工资。
select min(sal) from emp;38.查询出每个部门的人数、平均工资,只显示部门编号。
select count(ename),avg(sal),deptno from emp group by deptno;
39.查询出每种职位的最高和最低工资。
select min(sal),max(sal) from emp group by deptno;
40.查询平均工资高于2000的职位信息,以及从事此职位的雇员人数、平均工资。
select count(ename),avg(sal),job from emp group by job having avg(sal)>2000;
41查询出至少有一个员工的所有部门编号、名称,并统计出这些部门的平均工资、最低工资、最高工资。select deptno,dname,avg(sal),min(sal),max(sal) from (select min(sal),max(sal),deptno frpm emp group by deptno) q,dept d;
42.查询出部门名称和这些部门的员工信息(数量、平均工资),同时列出那些没有员工的部门。select d.dname,count(e.ename),avg(e.sal),e.deptno from emp e right join dept d on e.deptno=d.deptno group by e.deptno,d.dname; 43.插入自己和左右同桌的信息
insert into emp values(编号,姓名,职位,上级领导编号,雇佣日期,工资,奖金,部门编号);
44.修改右边/左边同桌的信息(工资,奖金,雇佣日期)
update emp set sal=值,comm=值,hriedate=值, where empno=值;
45.删除自己的个人信息
delete table emp where empno=值;