1.查询20号部门的所有员工信息
select * from emp where deptno = 20;
2.查询所有工种为CLERK的员工的工号、员工名和部门名
select e.empno,e.ename,d.dname from emp e,dept d where job = 'CLERK';
3.查询奖金(COMM)高于工资(SAL)的员工信息
select * from emp where comm > sal;
4.查询奖金高于工资的20%的员工信息
select * from emp where comm > 0.2*sal;
5.查询10号部门中工种为MANAGER和20号部门中工种为CLERK的员工的信息
select * from emp where deptno=10 and job='MANAGER' or deptno=20 and job='CLERK';
select * from emp where job='MANAGER' and deptno=10 union
select * from emp where job='CLERK' and deptno=20;
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;
select distinct job from emp where where comm>=0;
8.查询所有员工工资和奖金的和
select ename, (sal+nvl(comm,0)) as year_sal from emp;
9.查询没有奖金或奖金低于100的员工信息
select * from emp where comm is null or comm < 1000;
10.查询各月倒数第2天入职的员工信息
select * from emp where hiredate=last_day(hiredate)-1;
11.查询员工工龄大于或等于10年的员工信息
select * from emp where extract(year from current_date)-extract(year from hiredate)>=10;
12.查询员工信息,要求以首字母大写的方式显示所有员工的姓名
select initcap(ename) from emp;
13.查询员工名正好为6个字符的员工的信息
select * from emp where length(ename) = 6;
14.查询员工名字中不包含字母“S”员工
select * from emp where ename not like '%S%';
15.查询员工姓名的第2个字母为“M”的员工信息
select * from emp where ename like '_M%';
16.查询所有员工姓名的前3个字符
select substr(ename,0,3) from emp ;
select substr(ename,1,3) from scott.emp;
面试题:请问SUBSTR()函数截取的时候下标从0还是从1开始?
在Oracle数据库之中,SUBSTR()函数从0或1开始都是一样的;
SUBSTR()也可以设置为负数,表示由后指定截取的开始点;
Oracle_sql_(1)
最新推荐文章于 2021-12-26 14:29:40 发布
本文提供了多个实用的SQL查询案例,包括多表联查、条件筛选、字符串操作等,帮助读者掌握复杂查询技巧。
1547

被折叠的 条评论
为什么被折叠?



