Oracle 语句综合练习

/*1、使用基本查询语句.
(1)查询DEPT表显示所有部门名称.
(2)查询EMP表显示所有雇员名及其全年收入(月收入=工资+补助),处理NULL行,并指定列别名为"年收入"。(NVL(comm,0) comm取空值时用0替代)
(3)查询显示不存在雇员的所有部门号。
2、限制查询数据
(1)查询EMP表显示工资超过2850的雇员姓名和工资。
(2)查询EMP表显示工资不在1500~2850之间的所有雇员及工资。
(3)查询EMP表显示代码为7566的雇员姓名及所在部门代码。
(4)查询EMP表显示部门10和30中工资超过1500的雇员名及工资。
(5)查询EMP表显示第2个字符为"A"的所有雇员名其工资。
(6)查询EMP表显示补助非空的所有雇员名及其补助。*/

-- (1)查询DEPT表显示所有部门名称.
select d.dname
from dept d;

--(2)查询EMP表显示所有雇员名及其全年收入(月收入=工资+补助),处理NULL行,并指定列别名为"年收入"。(NVL(comm,0) comm取空值时用0替代)
select e.ename,(e.sal+NVL(e.comm,0))*12 "年收入"
from emp e;

--(3)查询显示不存在雇员的所有部门号。
select d.deptno
from dept d,emp e
where d.deptno=e.deptno group by d.deptno
having count(e.empno)=0;

select e.deptno
from emp e
where e.deptno not in
(
select d.deptno
from dept d
);

-- (1)查询EMP表显示工资超过2850的雇员姓名和工资。
select e.ename "雇员姓名", e.sal "工资"
from emp e
where e.sal>2850;


--(2)查询EMP表显示工资不在1500~2850之间的所有雇员及工资。
select e.ename "雇员姓名", e.sal "工资"
from emp e
where e.sal>2850 or e.sal<1500;


-- (3)查询EMP表显示代码为7566的雇员姓名及所在部门代码。
select e.ename "雇员姓名", e.deptno "部门代码"
from emp e
where e.empno=7566;


-- (4)查询EMP表显示部门10和30中工资超过1500的雇员名及工资。
select e.ename "雇员姓名", e.sal "工资"
from emp e
where e.deptno= some(10,30) and e.sal>1500;


-- (5)查询EMP表显示第2个字符为"A"的所有雇员名其工资。
select e.ename "雇员姓名", e.sal "工资"
from emp e
where e.ename like '_A%';


-- (6)查询EMP表显示补助非空的所有雇员名及其补助。
select e.ename "雇员姓名",e.comm "补助"
from emp e
where e.comm is not null;

猜你喜欢

转载自www.cnblogs.com/luojack/p/10859719.html