Oracle_sql_(1)

本文提供了多个实用的SQL查询案例,包括多表联查、条件筛选、字符串操作等,帮助读者掌握复杂查询技巧。

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()也可以设置为负数,表示由后指定截取的开始点;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZHOU_VIP

您的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值