oracle之单行函数之分组函数之课后练习
生活随笔
收集整理的這篇文章主要介紹了
oracle之单行函数之分组函数之课后练习
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
33. 查詢 employees 表中有多少個部門select count(distinct department_id)from employees 34. 查詢全公司獎金基數的平均值(沒有獎金的人按 0 計算)select avg(nvl(commission_pct, 0))from employees 35. 查詢各個部門的平均工資--錯誤: avg(salary) 返回公司平均工資, 只有一個值; 而 department_id 有多個值, 無法匹配返回select department_id, avg(salary)from employees **在 SELECT 列表中所有未包含在組函數中的列都應該包含在 GROUP BY 子句中--正確: 按 department_id 進行分組select department_id, avg(salary)from employeesgroup by department_id36. Toronto 這個城市的員工的平均工資SELECT avg(salary)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id
WHERE city = 'Toronto' 37. (有員工的城市)各個城市的平均工資SELECT city, avg(salary)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id
GROUP BY city 38. 查詢平均工資高于 8000 的部門 id 和它的平均工資. SELECT department_id, avg(salary)
FROM employees e
GROUP BY department_id
HAVING avg(salary) > 8000 39. 查詢平均工資高于 6000 的 job_title 有哪些SELECT job_title, avg(salary)
FROM employees e join jobs j
ON e.job_id = j.job_id
GROUP BY job_title
HAVING avg(salary) > 6000
1. 組函數處理多行返回一行嗎?
是
2. 組函數不計算空值嗎?
是
3. where子句可否使用組函數進行過濾?
不可以,用having替代
4. 查詢公司員工工資的最大值,最小值,平均值,總和
a) select max(salary),min(salary),avg(salary),sum(salary)
b) from employees
5. 查詢各job_id的員工工資的最大值,最小值,平均值,總和
a) select job_id,max(salary),min(salary),avg(salary),sum(salary)
b) from employees
c) group by job_id
6. 選擇具有各個job_id的員工人數
a) select job_id,count(employee_id)
b) from employees
c) group by job_id
7. 查詢員工最高工資和最低工資的差距(DIFFERENCE)
a) select max(salary),min(salary),max(salary)-min(salary) "DIFFERENCE"
b) from employees
8. 查詢各個管理者手下員工的最低工資,其中最低工資不能低于6000,沒有管理者的員工不計算在內
a) select manager_id,min(salary)
b) from employees
c) where manager_id is not null
d) group by manager_id
e) having min(salary) >= 6000
9. 查詢所有部門的名字,location_id,員工數量和工資平均值
a) select department_name,location_id,count(employee_id),avg(salary)
b) from employees e right outer join departments d
c) on e.department_id = d.department_id
d) group by department_name,location_id
10. 查詢公司在1995-1998年之間,每年雇用的人數,結果類似下面的格式
total 1995 1996 1997 1998
20 3 4 6 7select count(*) "total",count(decode(to_char(hire_date,'yyyy'),'1995',1,null)) "1995",count(decode(to_char(hire_date,'yyyy'),'1996',1,null)) "1996",count(decode(to_char(hire_date,'yyyy'),'1997',1,null)) "1997",count(decode(to_char(hire_date,'yyyy'),'1998',1,null)) "1998"
from employees
where to_char(hire_date,'yyyy') in ('1995','1996','1997','1998')
?
總結
以上是生活随笔為你收集整理的oracle之单行函数之分组函数之课后练习的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于博客搬家
- 下一篇: DB9接口定义、232串口公头和母头的引