根据Oracle数据库scott模式下的emp表和dept表
题目要求:根据Oracle数据库scott模式下的emp表和dept表,完成下列操作。
(1) 查询20号部门的所有员工信息。
select * from emp where deptno = 20;
(2) 查询所有工种为CLERK的员工的工号、员工名和部门名。
select empno,ename,deptno from emp where job like 'CLERK';
(3) 查询奖金(COMM)高于工资(SAL)的员工信息。
select * from emp where comm > sal;
(4) 查询奖金高于工资的20%的员工信息。
select * from emp where comm > (sal*0.2);
(5) 查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息。
select * from emp
where (deptno = 10 and job like 'MANAGER') or (deptno = 20 and job like 'CLERK');
(6) 查询所有工种不是MANAGER和CLERK,且工资大于或等于2000的员工的详细信
息。
select * from emp
where job not in ('MANAGER','CLERK') and sal >= 2000 ;
(7) 查询有奖金的员工的不同工种。
select distinct job from emp where comm is not null;
(8) 查询所有员工工资和奖金的和。
select ename,(sal+nvl(comm,0)) salcomm from emp;
(9) 查询没有奖金或奖金低于100的员工信息。
select * from emp where (comm is null or comm < 100) ;
(10) 查询各月倒数第2天入职的员工信息。
select * from emp where hiredate in (select (last_day(hiredate)-1) from emp);
(11) 查询员工工龄大于或等于10年的员工信息。
select * from emp where (sysdate - hiredate)/365 >= 10 ;
(12) 查询员工信息,要求以首字母大写的方式显示所有员工的姓名。
select upper(substr(ename,1,1)) || lower(substr(ename,2,length(ename)-1)) from emp;
(13) 查询员工名正好为6个字符的员工的信息。
select * from emp where length(ename)= 6 ;
(14) 查询员工名字中不包含字母“S”员工。
select * from emp where ename not in (select ename from emp where ename like '%S%') ; select * from emp where ename not like ‘%S%’;
(15) 查询员工姓名的第2个字母为“M”的员工信息。
select * from emp where ename like '_M%';
(16) 查询所有员工姓名的前3个字符。
select substr(ename,1,3) from emp ;
(17) 查询所有员工的姓名,如果包含字母“s”,则用“S”替换。
select replace(ename,'s','S') from emp ;
(18) 查询员工的姓名和入职日期,并按入职日期从先到后进行排列。
select ename,hiredate from emp order by hiredate asc ;
(19) 显示所有的姓名、工种、工资和奖金,按工种降序排列,若工种相同则按工资升序
排列。
select ename,job,sal,comm from emp order by job desc,sal asc ;