SQL 실습 2 : Restricting and Sorting Data

FMA·2024년 2월 21일

[코딩테스트] SQL

목록 보기
1/2
post-thumbnail

LiveSQL 사용, DB : HR Object and Data

  1. 급여가 $12,000를 넘는 사원의 이름과 급여를 표시
SELECT first_name, salary
FROM employees
WHERE salary >= 12000;
  1. 사원 번호가 176인 사원의 이름과 부서 번호 표시
SELECT first_name, department_id
FROM employees
WHERE EMPLOYEE_ID=176;
  1. 급여가 $5,000에서 $12,000 사이에 포함되지 않는 모든 사원의 이름과 급여를 표시
select first_name, salary
from employees
where salary not between 5000 and 12000;
  1. 2007년 2월 20일과 2007년 5월 1일 사이에 입사한 사원의 이름, 업무 ID 및 시작일을 표시하되, 시작일을 기준으로 오름차순으로 정렬하는 질의 – 날짜는 DATE ‘2007-02-20’ 같은 형태로 표시하면 됨
select first_name, department_id, hire_date
from employees
where hire_date between to_date('2007-2-10', 'YYYY-MM-DD') and to_date ('2007-5-1', 'YYYY-MM-DD')order by hire_date asc;
  1. 부서 20 및 50에 속하는 모든 사원의 이름과 부서 번호를 이름을 기준으로 영문자순으로 표시
select first_name, department_id
from employees
where department_id = 20 or department_id = 50order by first_name asc;
  1. 급여가 $5,000와 $12,000 사이이고 부서 번호가 20 또는 50인 사원의 이름과 급여를 나열하고, 열 레이블을 Employee와 Monthly Salary로 각각 지정
select first_name "Employee", department_id "Monthly Salary"
from employees
where (salary between 5000 and 12000) and (department_id = 20 or department_id = 50);
  1. 1994년에 입사한 모든 사원의 이름과 입사일을 표시
select first_name, hire_date
from employees
where hire_date between to_date('1994-1-1', 'YYYY-MM-DD') and to_date ('1994-12-31', 'YYYY-MM-DD');
  1. 관리자가 없는 모든 사원의 이름과 업무 ID를 표시
select first_name, job_id
from employees
where manager_id is NULL;
  1. 커미션을 받는 모든 사원의 이름, 급여 및 커미션을 급여 및 커미션을 기준으로 내림차순으로 정렬하여 표시
select first_name, salary, commission_pct
from employees
order by salary, commission_pct desc;
  1. 이름의 세 번째 문자가 a인 모든 사원의 이름을 표시
select first_name
from employees
where first_name like '__a%';
  1. 이름에 a와 e가 있는 모든 사원의 이름을 표시
select first_name
from employees
where first_name like '%a%' and first_name like '%e%';
  1. 업무가 영업 사원(SA_REP) 또는 사무원(ST_CLERK)이면서 급여가 $2,500, $3,500 또는 $7,000가 아닌 모든 사원의 이름, 업무 및 급여를 표시
select first_name, job_id, salary
from employees
where (job_id = 'SA_REP' or job_id = 'ST_CLERK') and salary between 2500 and 3500;
  1. 커미션 비율이 20%인 모든 사원의 이름, 급여 및 커미션을 표시
select first_name, salary, commission_pct
from employees
where commission_pct = 0.2

0개의 댓글