一、 單選題
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