5시간코딩

[in, not in] 부서가 10,30,50이 아닌 사원들의 employee_id, last_name, department_id 를 출력하세요. 본문

문제풀기/테이블 조작 관련 문제

[in, not in] 부서가 10,30,50이 아닌 사원들의 employee_id, last_name, department_id 를 출력하세요.

5시간코딩 2019. 4. 4. 11:56

1. oracle

explain plan for 
select employee_id, last_name, department_id
from employees
where department_id not in (10,30,50);
select * from table(dbms_xplan.display(null,null,'typical'));

 

실행계획:

------------------------------------------------------------------------------- 
| Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     | 
------------------------------------------------------------------------------- 
|   0 | SELECT STATEMENT  |           |    56 |   840 |     3   (0)| 00:00:01 | 
|*  1 |  TABLE ACCESS FULL| EMPLOYEES |    56 |   840 |     3   (0)| 00:00:01 | 
------------------------------------------------------------------------------- 
  
Predicate Information (identified by operation id): 
--------------------------------------------------- 
  
   1 - filter("DEPARTMENT_ID"<>50 AND "DEPARTMENT_ID"<>30 AND  
              "DEPARTMENT_ID"<>10)

 

 

 

 

 

 

2. r

1)

emp[!emp$DEPARTMENT_ID %in% c(10,30,50),c('EMPLOYEE_ID','LAST_NAME','DEPARTMENT_ID')]

2)

subset(emp,!DEPARTMENT_ID %in% c(10,30,50),select=c(EMPLOYEE_ID,LAST_NAME,DEPARTMENT_ID))

3)
library(sqldf)
sqldf("select employee_id, last_name, department_id
      from emp
      where department_id not in (10,30,50)")
4)
library(dplyr)
emp%>%
  filter(!DEPARTMENT_ID %in% c(10,30,50))%>% ### NA가 생략되어서 나옴
  select(EMPLOYEE_ID,LAST_NAME,DEPARTMENT_ID)

 

 

 

3. python

1)

import csv
file = open("c:/data/employees.csv","r")
emp_csv = csv.reader(file)
title = [next(emp_csv)]
res = []
for i in emp_csv:
    if i[-1] not in ['10','30','50']:
        emp.append([i[0],i[2],i[-1]])
print(res)

2)

import pandas as pd

df=pd.read_csv("c:/data/employees.csv")

df.loc[df['DEPARTMENT_ID'].isin(['10','30','50']),['EMPLOYEE_ID','LAST_NAME','DEPARTMENT_ID']]