Oracle数据库查询语句

编写以下查询的SQL语句,以scott用户的emp表和dept表作为查询数据:

1.列出至少有一个员工的所有部门。

SQL语句:

select * from SCOTT.DEPT
where deptno in
(select distinct deptno from SCOTT.DEPT);

查询结果:

 

2.列出所有员工的姓名及其直接上级的姓名。

SQL语句:

select e.ename 员工姓名,m.ename 上级姓名
from scott.emp e,scott.emp m
where m.empno=e.mgr;

查询结果:

 

3.列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门。

SQL语句:

select d.dname,e.*
from scott.dept d,scott.emp e
where d.deptno=e.deptno(+);

查询结果:

 

4.列出最低薪金大于1500 的各种工作。

SQL语句:

select job 工作,min(sal) 最低薪金
from SCOTT.EMP
group by job
having min(sal)>1500;

查询结果:

 

5.列出薪金高于公司平均薪金的所有员工。

SQL语句:

select *
from SCOTT.EMP
where  sal>(select avg(sal) from SCOTT.EMP);

查询结果:

 

6.列出薪金等于部门30 中员工的薪金的所有员工的姓名和薪金。

SQL语句:

select ename,sal,deptno
from SCOTT.EMP
where sal in (select sal from SCOTT.EMP where deptno=30);

查询结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值