【sql】訓練三
1. Ben的領導是誰(Ben向誰報告)。
SQL> select first_name,manager_id from employees where manager_id =(select manager_id from employees where first_name='Ben');
2. Ben領導誰。(誰向Ben報告)。
SQL> select first_name,employee_id from employees where manager_id = (select employee_id from employees where first_name='Ben');
3. 哪些員工和Biri(last_name)同部門
SQL> select last_name,department_id from employees where department_id = (select department_id from employees where last_name='Biri');
4. 哪些員工跟Smith(last_name)做一樣職位
SQL> select last_name,job_id from employees where job_id = (select distinct job_id from employees where last_name='Smith');
5. 哪些員工跟Biri(last_name)不在同一個部門
SQL> select last_name,job_id from employees where job_id not in ((select distinct job_id from employees where last_name='Smith'));
6. 整個公司中,最高工資和最低工資相差多少
SQL> select max(salary),min(salary),max(salary)-min(salary) gzc from employees;
MAX(SALARY) MIN(SALARY) GZC
----------- ----------- ----------
24000 2100 21900
7. 顯示整個公司的最高工資、最低工資、工資總和、平均工資,保留到整數位。
SQL> select max(salary),min(salary),sum(salary),trunc(avg(salary)) from employees;
MAX(SALARY) MIN(SALARY) SUM(SALARY) TRUNC(AVG(SALARY))
----------- ----------- ----------- ------------------
24000 2100 691416 6461
8. 整個公司有多少個領導
SQL> select count(manager_id) from employees;
COUNT(MANAGER_ID)
-----------------
106
9. 各個部門中工資大於1500的員工人數
SQL> select department_id,count(*) from employees where
2 salary > 1500 group by department_id;
10.該部門中工資高於1000的員工數量超過2人,列出符合條件的部門:顯示部門名字
SQL> select department_name from departments where department_id in (select department_id from employees where salary>1000 group by department_id having count(employee_id)>2);
DEPARTMENT_NAME
------------------------------
Finance
Purchasing
Executive
Shipping
Sales
IT
6 rows selected.
11. 哪些員工的工資,高於整個公司的平均工資,列出員工的名字和工資(降序)
SQL> select first_name,salary from employees where salary > (select avg(salary) from employees);
12. 哪些員工的工資,介於32和33部門平均工資之間
SQL> select first_name,salary from employees where salary between (select avg(salary) from employees where department_id =33)
2 and
3 ( select avg(salary) from employees where department_id =32 );
13.列出各個部門中工資最高的員工的資訊:名字、部門號、工資
SQL> select department_id,last_name,salary from employees where (department_id,salary) in (select department_id,max(salary) from employees group by department_id) order by 1;
14.哪些部門的人數比32號部門的人數多
SQL> select department_id,count(last_name) from employees group by department_id
2 having count(last_name) > (select count(last_name) from employees where department_id = 32);
15. 求出每個部門的僱員數量
SQL> select department_id,count(first_name) from
2 employees group by department_id;
16. 查詢出比7654工資要高的全部僱員的資訊
SQL> select FIRST_NAME,SALARY from employees where salary > 7656;
17. 要求查詢工資比7654高,同時與7788從事相同工作的全部僱員
SQL> select first_name,salary from employees where salary > 7654 and job_id = (select job_id from employees where salary = 7788);
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2127034/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【sql】訓練五SQL
- 【sql】訓練四SQL
- 【sql】訓練二SQL
- 【sql】訓練一SQL
- 【訓練】sql訓練、建立和管理表、約束、檢視及其他資料庫物件SQL資料庫物件
- Bug除錯專項訓練三筆記除錯筆記
- HTK 第三章 模型訓練示例模型
- 從DDPM到DDIM(三) DDPM的訓練與推理
- 【vjudge訓練記錄】11月個人訓練賽1
- acm訓練題ACM
- IOS Swift 訓練iOSSwift
- 4.17訓練賽
- 自訓練 + 預訓練 = 更好的自然語言理解模型模型
- [SQL Server玩轉Python] 三.SQL Server儲存過程實現Python鳶尾花決策樹訓練及預測SQLServerPython儲存過程
- 9.6-小訓練 三分小板子+單調棧
- CANN訓練營第三季_基於昇騰PyTorch框架的模型訓練調優_讀書筆記PyTorch框架模型筆記
- 【專題訓練】字串字串
- java小白訓練營Java
- 機器學習的訓練集機器學習
- YOLO2訓練YOLO
- 資料集訓練
- CF專項訓練
- 機率期望訓練
- 24.8.18 DP訓練
- dp專題訓練
- 專項訓練們
- 騰訊面試官親授:三個遊戲策劃思維訓練面試遊戲
- 馬上報名 | Google Play線上訓練營三月課程Go
- PyTorch 模型訓練實⽤教程(程式碼訓練步驟講解)PyTorch模型
- 2、PyTorch訓練YOLOv11—訓練篇(detect)—Windows系統PyTorchYOLOv1Windows
- sql 練習SQL
- 【學校訓練記錄】10月個人訓練賽3個人題解
- 【預訓練語言模型】 使用Transformers庫進行BERT預訓練模型ORM
- 【LLM訓練系列】NanoGPT原始碼詳解和中文GPT訓練實踐NaNGPT原始碼
- 神經網路訓練的三個基本概念Epoch, Batch, Iteration神經網路BAT
- 【OCR技術系列之三】大批量生成文字訓練集
- 自我訓練 – PHP函式PHP函式
- java工廠模式訓練Java模式