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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- pl/sql練習SQL
- pl/sql 練習SQL
- SQL 練習題SQL
- SQL練習題SQL
- oracle sql練習題OracleSQL
- SQL練習00015SQL
- SQL練習00012SQL
- sql 語句練習 In MySQLMySql
- sql 語句練習(2)SQL
- SQL Server遊標使用練習SQLServer
- sql 語句練習(3) In MySQLMySql
- sql查詢入門練習題SQL
- Day5-SQL綜合練習(Datawhale)SQL
- 牛客SQL練習第21題SQL
- Oracle SQL select練習語句OracleSQL
- SQL*Loader 筆記 (一) 熱身練習SQL筆記
- SQL學習和練習的好地方(http://sqlzoo.cn)SQLHTTP
- [MySQL光速入門]008 SQL強化練習MySql
- 【sql】訓練五SQL
- 【sql】訓練四SQL
- 【sql】訓練三SQL
- 【sql】訓練二SQL
- 【sql】訓練一SQL
- [MySQL光速入門]009 SQL強化練習答案MySql
- 笨辦法學 Python · 續 練習 39:SQL 建立PythonSQL
- 新手練習:Python練習題目Python
- MYSQL練習1: DQL查詢練習MySql
- 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線上練習網站(http://sqlzoo.cn)答案解析(3)SQL網站HTTP
- sql線上練習網站(http://sqlzoo.cn)答案解析(1)SQL網站HTTP
- sql線上練習網站(http://sqlzoo.cn)答案解析(2)SQL網站HTTP
- 簡單練習Microsoft SQL Server MERGE同步兩個表ROSSQLServer