sql 練習
要求:入職在2005年之前(老員工才有資格中獎 ),並且中獎員工是尾數為0的員工,我們要聯絡所在部門頒發獎品。
select d.department_id, d.department_name from departments d where exists (select 1 from employees e where e.department_id = d.department_id and e.employee_id in (110, 120, 130, 140, 150, 160, 170, 180, 190, 200)) and not exists (select 1 from employees e where e.department_id = d.department_id and e.hire_date > to_date('2005-01-01', 'yyyy-mm-dd'))
執行計劃
丟東西了,日啊
(select d.department_id, d.department_name, max(case when e.employee_id IN (110, 120, 130, 140, 150, 160, 170, 180, 190, 200) then 1 else null end) as existscontion, max(case when e.hire_date > to_date('2005-01-01', 'yyyy-mm-dd') then 1 else null end) as notexistscondition, d.department_id from departments d left join employees e on d.department_id = e.department_id group by d.department_id, d.department_name ,d.department_id)
結果
select rs.department_id, rs.department_name from (select d.department_id, d.department_name, max(case when e.employee_id IN (110, 120, 130, 140, 150, 160, 170, 180, 190, 200) then 1 else null end) as existscontion, max(case when e.hire_date > to_date('2005-01-01', 'yyyy-mm-dd') then 1 else null end) as notexistscondition from departments d left join employees e on d.department_id = e.department_id group by d.department_id, d.department_name) rs where existscontion is not null and notexistscondition is null
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29990276/viewspace-1782010/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL練習題SQL
- SQL練習00012SQL
- SQL練習00015SQL
- sql查詢入門練習題SQL
- 牛客SQL練習第21題SQL
- Day5-SQL綜合練習(Datawhale)SQL
- [MySQL光速入門]008 SQL強化練習MySql
- [MySQL光速入門]009 SQL強化練習答案MySql
- 簡單練習Microsoft SQL Server MERGE同步兩個表ROSSQLServer
- markdown 使用練習練習
- SQL經典練習題48道之一(1-10)SQL
- SQL經典練習題48道之二(11-19)SQL
- SQL經典練習題48道之三(20-25)SQL
- SQL經典練習題48道之四(26-30)SQL
- SQL經典練習題48道之五(31-35)SQL
- SQL經典練習題48道之六(36-40)SQL
- SQL經典練習題48道之七(41-48)SQL
- 【躍遷之路】SQL語句刻意練習(最後更新:2018.06.25)SQL
- Hive SQL必刷練習題:同時線上人數問題(*****)HiveSQL
- 新手練習:Python練習題目Python
- MYSQL練習1: DQL查詢練習MySql
- 招聘要求裡的「熟練使用 SQL」 你熟練麼?SQL
- [資料庫]50道經典SQL練習題,使用MySQL5.7解答資料庫MySql
- MySQL基礎練習20題,看看你的sql基礎man不manMySql
- python練習Python
- MySQL練習MySql
- ddl練習
- latex練習
- MySQ練習
- openGauss練習
- U7-11課綜合練習+12課階段測評練習——複習練習題目
- SQL學習SQL
- SQL 學習SQL
- SQL複習SQL
- python 練習0000Python
- C++練習C++
- shell練習題
- 【練習】canvas——flappyBirdCanvasAPP
- Python 練習題Python