Oracle数据库默认三张表的sql练习62题
(1) 查询20号部门的所有员工信息。
Select * from emp e where e.deptno = 20;
(2) 查询所有工种为CLERK的员工的工号、员工名和部门名。
select empno ,ename,deptno from emp where job='CLERK';
select ename,sal,comm from emp where comm > sal;
(3) 查询奖金(COMM)高于工资(SAL)的员工信息。
select ename,sal,comm from emp where comm > sal;
(4) 查询奖金高于工资的20%的员工信息。
select ename,sal,comm from emp where comm > (sal*0.2);
(5) 查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息。
select ename,job,deptno from emp where job ='MANAGER'and deptno = 10 or job='CLERK' and deptno=20;
(6) 查询所有工种不是MANAGER和CLERK,且工资大于或等于2000的员工的详细信息。
select * from emp where job !='MANAGER' and job !='CLERK' and sal >= 2000;
(7) 查询有奖金的员工的不同工种。
select distinct job from emp where comm is not null;
(8) 查询所有员工工资和奖金的和。
select sum(sal) from emp;
(9) 查询没有奖金或奖金低于100的员工信息。
select ename,comm from emp where comm is null or nvl(comm,0) < 100;
(10) 查询各月倒数第2天入职的员工信息。
Select*fromempwhere(last_day(hiredate)-2) = hiredate;
(11) 查询员工工龄大于或等于10年的员工信息。
select ename, hiredate from emp where (to_char(sysdate, 'yyyy') - to_char(hiredate, 'yyyy')) >= 10;
(12) 查询员工信息,要求以首字母大写的方式显示所有员工的姓名。
select initcap(ename) from emp;
(13) 查询员工名正好为6个字符的员工的信息。
select ename from emp where length(ename)=6;
(14) 查询员工名字中不包含字母“S”员工。
select ename from emp where ename not like '%S%';
(15) 查询员工姓名的第2个字母为“M”的员工信息。
select ename 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 , sal desc;
(20) 显示所有员工的姓名、入职的年份和月份,若入职日期所在的月份排序,若月份相同则按入职的年份排序。
select ename,
extract(YEAR from hiredate) year1,
extract(MONTH from hiredate) month1
from emp
order by month1 ,year1;
(21) 查询在2月份入职的所有员工信息。
select * from emp where extract(</