ExSchool01

a--부서테이블의 모든 데이터를 출력하라

select * from emp;

--emp테이블에서 각 사원의 직업, 사원번호 이름, 입사일을 출력하라.

select job 직업, empno 사원번호, ename 이름, hiredate 입사일 from emp;



--emp테이블에서 직업을 출력하되, 각 항목(row가 중복되지 않게 출력하라.

select distinct job 직업 from emp;


/*distinct : select문의 결과에서 중복 행을 제거한다.이 키워드를 지정하지 않으면

중복행을 포함한 모든 행이 반환된다. 예를 들어

distinct를 지정하지 않고 job을 모든 제품 id를 선택할 경우

14개의 행이 반환된다.*/


--급여가 2850 이상인 사원의 이름 및 급여를 표시하는 출력하라.

select ename 사원이름, sal 급여 from emp where sal >= 2850;


--사원번호가 7566인 사원의 이름 및 부서번호를 표시하는 출력하라.

select ename 사원이름, deptno 부서번호 from emp where empno = '7566';


--급여가 1500이상 ~ 2850이하의 범위에 속하지 않는 모든 사원의 이름 및 급여를

출력하라.


select ename 이름, sal 급여 

from emp 

where sal not 

between 1500 and 2850;


--1981년 2월 20일 ~ 1981년 5월 1일에 입사한 사원의 이름, 직업 및 입사일을

출력하라. 입사일을 기준으로 해서 오름차순으로 정렬하라.


select ename 이름, job 직업,hiredate 입사일

from emp

where hiredate between '1981-02-20' and '1981-05-01'

order by hiredate asc;



--10번 및 30번 부서에 속하는 모든 사원의 이름과 부서번호를 출력하되

이름을 알파벳순으로 정렬하여 출력하라.


select ename, deptno 

from emp 

where deptno in(10, 30)

order by ename asc;


--11 커미션을 받는 모든 사원의 이름 급여 및 커미션을 출력하되

--급여를 기준으로 내림차순으로 정렬하여 출력하라

select ename,sal,comm

from emp

where comm != 0 and comm is not null

order by sal desc;


--12 이름의 세 번째 문자가 A인 모든 사원의 이름을 출력하라.

select ename

from emp

where ename 

like '__A%';


--13 이름에 L이 두 번 들어가며 부서 30에 속해있는 사원의 이름을 출력하라.

select deptno, ename from emp where ename like '%L%L%' and deptno = 30;


--14 직업이 Clerk 또는 Analyst이면서 급여가 1000, 3000, 5000이 아닌 모든 사원의 이름, 직업 및 급여를 출력하라.

select ename, job, sal 

from emp 

where job in('CLERK','ANALYST') and sal not in(1000, 3000, 5000);


--런던 지역에 근무하는 사원의 이름, 급여, 부서코드 조회


select * from emp;


select a.first_name 사원이름,salary 급여,a.department_id 부서코드

from employees a, departments b

where a.department_id = b.department_id

and b.location_id =(select location_id

from locations

where lower(city) ='london');


select first_name

from employees

where department_id =40;


--자신의 상관이 kelly 인 사원의 이름과 급여 조회

select first_name, salary

from employees

where manager_id = (select employee_id

from employees

where lower(first_name) = 'adam');


-- 유럽 대륙에 근무하는 사원의 이름과 급여조회


select first_name, salary

from employees a, departments b, locations c, countries d

where a.department_id = b.department_id

and b.location_id = c.location_id

and c.country_id = d.country_id

and d.region_id = (select region_id

from regions

where region_name = 'Europe');



select

    first_name, last_name, email, salary, J.job_id, job_title

from

    employees E, jobs J

where

    E.job_id = J.job_id and

    salary = (select min(salary) from employees);



select

    first_name, last_name, email, salary, j.job_id, job_title

from employees E, jobs J

where

    E.job_id = J.job_id and

    salary = (select min(salary) from employees);


select first_name, last_name, email, J.job_id, job_title

from employees E, jobs J

where

    E.job_id = J.job_id and

    salary= (select min(salary) from employees);



프로그래밍 | 카테고리의 다른 글

  • Or05Date  (0)
  • 2017.11.15
  • Or04TypeConvert  (0)
  • 2017.11.15
  • Or03String  (0)
  • 2017.11.15
  • Or02Number  (0)
  • 2017.11.15
  • Or14View  (0)
  • 2017.11.14
    TAGS.

    Comments