oracle(1)

一、 单选题

1. 能查询用户的平均年龄的是: (D
A: select max(age) from user;
B: select count(age) from user;
C: select sum(age) from user;
D: select avg(age) from user;

2. 已知表T1中有2行数据,T2中有3行数据,执行SQL语句"select a.* from T1 a, T2 b"后,返回行数为:(D)
A:2行
B:3行
C:5行
D:6行

//多表查询没有指定连接条件,会导致笛卡尔积的出现,返回行数等于2张表的行数乘积,返回6行记录

3.关于右外连接查询的说法不正确的是: (A
A:两表进行右外连接查询和左外连接查询查询出的结果都是一样的
B:右外连接查询是以右侧的表为主表
C:右外连接查询可以和左外连接查询相互转换
D: 右外连接查询查询时右表中的记录会全部显示

4.关于Oracle数据库的概念说明以下不正确的是: (D
A:对象关系型的数据库管理系统
B:既提供关系数据库系统的功能,又提供面向对象的数据库系统功能,并且提高了数据的完整性
C:在管理信息系统、企业数据处理、因特网及电子商务等领域使用非常广泛
D:在数据安全性与数据完整性控制方面性能不佳

5.下面关于count函数的说法正确的是 (B
A: select count() from emp,的返回结果可能是个小数,也可能是整数
B: count()中的参数如果是某个字段,就以当前字段计数
C: select count(
) from emp,可以查询出emp表中全部数据
D: select count(sal) from emp,可以计算出员工的总工资

6.能查询年龄小于15岁的女学生信息: (D
A: select * from users where age<15 and sex=女
B: select * from users where age<15 or sex=‘女’
C: select * from users where id<15 and sex=‘女’
D: select * from users where age<15 and sex=‘女’

7.对SQL语句的描述中,下列说法不正确的有 (C
A: 使用关键字distinct消除冗余
B: where用于指定筛选条件
C: sql关键字区分大小写
D: 字符串比较按照字典排序

8.
having , where , group by 的正确执行顺序是( D
A:having,where,group by
B:group by,having,where
C:where,having,group by
D:where ,group by,having

查询中用到的关键词主要包含六个,并且他们的顺序依次为
select–from–where–group by–having–order by

9.观察下表ORDERS和CUSTOMERS
在这里插入图片描述
下面SQL语句的执行结果是(D
在这里插入图片描述
A:
在这里插入图片描述
B:
在这里插入图片描述
C:
在这里插入图片描述

D:查询失败,因为子查询的返回结果不止一行
E:查询失败,因为子查询和主查询用的不是同一张表

10.关系模型的数据结构是(C
A:数组结构
B:图结构
C:二维结构
D:树结构
E:链表结构

二、SQL综合(使用Soctt数据库)

1.查询所有从事"CLERK"工作的雇员姓名及其部门名称、部门人数。

select e.ename,d.dname,a.人数
from emp e,dept d,
(select count(*) as "人数",e.deptno
from emp e
group by e.deptno ) a
where e.deptno = d.deptno and e.job = 'CLERK'
and d.deptno = a.deptno 

在这里插入图片描述

2.查询在部门"sales"(销售部)工作的员工的姓名,假定不知道销售部的部门编号。

select ename from emp 
where deptno= (select deptno from dept where lower(dname)='sales' );

在这里插入图片描述

3.查询出没有员工的那个部门的部门编号和部门名称

SELECT d.deptno,d.dname FROM emp e, dept d
WHERE e.deptno(+)=d.deptno AND e.empno IS NULL

在这里插入图片描述

4.查询职员领导信息,要求领导工资大于4000

select distinct m.* from emp e,emp m 
where
m.sal >4000 and e.mgr=m.empno;

or

select * from emp e 
where 
e.empno in (select
distinct m.mgr from emp m where m.mgr is NOT NULL)
and
e.sal > 4000

在这里插入图片描述
5.显示职员工资的最大差额。

select distinct max(sal)-min(sal) as 最大差额 from emp;   //4200

6.显示所有雇员名及其全年收入(工资+补助),并指定列别名“年收入”。

select emp.ename as 雇员名,nvl2(comm,comm+sal,sal)*12 as 年收入 from emp;  

or

select emp.ename as 雇员名,(sal+NVL(comm,0))*12 as 年收入 from emp;

在这里插入图片描述

7.显示所有雇员的平均工资、总计工资、最高工资、最低工资

select round(avg(emp.sal),2) as 平均工资 , sum(emp.sal) as 总计工资,
max(emp.sal) as 最高工资, min(emp.sal) as 最低工资
from emp ;

在这里插入图片描述

8.查询KING所在单位的单位编号\单位名称\单位人数。

select emp.deptno 部门名称,dname 部门名,count(1) 人数 
from
emp,dept 
where
emp.deptno=dept.deptno 
and 
emp.deptno=(select deptno from emp where
ename='KING') group by emp.deptno,dname;

or

select e.deptno as 部门号,d.dname as 部门名称,
(select count(*) from (select deptno from emp
where deptno in (select deptno from emp where ename='KING') ) ) as 部门人数
from  emp e, dept d
where 
e.deptno = d.deptno 
and 
e.ename = 'KING';

在这里插入图片描述

9.找出人力成本最高的部门

select d.deptno,d.dname,SUM(e.sal) 
from dept d,emp e 
where d.deptno = e.deptno
group by d.deptno,d.dname 
having sum(e.sal) >= all (select sum(sal) from emp  group by deptno);

在这里插入图片描述

10.显示部门20的员工姓名、部门编号以及在同一部门工作的所有员工

select e.deptno, e.ename, m.deptno,m.ename
from emp e join emp m on e.deptno = m.deptno
where e.deptno = 20 and e.empno != m.empno

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章