1. 학생 테이블에서 학생 이름과 키,몸무게, 표준체중을 출력하기 표준 체중은 키에서 100을 뺀 값에 0.9를 곱한 값이다.
select name, height, (height-100)*0.9 표준체중 from student
2. 101 번 학과 학생 중에서 3학년 이상인 학생의 이름, 아이디, 학년을 출력하기
select name, id, grade 학년 from student
where grade between 3 and 4 and deptno1 in 101
---------------------------------------------------------
select name, id, grade 학년 from student--***
where grade >= 3 and deptno1=101
3. 키가 165 이상 175 이하인 학생의 이름, 학년, 키를 출력하여라.
select name, grade 학년, height 키 from student
where height between 165 and 175
4. 학생 중 이름의 끝자가 '훈'인 학생의 학번, 이름, 부서코드 출력하기
select studno 학번, name 이름, deptno1 학과코드 from student
where name like '%훈'
---------------------------------------------------------------------
select studno 학번, name 이름, deptno1 학과코드 from student--***
where substr(name,-1) = '훈'
5. 학생 중 전화번호(tel)가 서울지역인 학생의 이름, 학번, 전화번호 출력하기
select name, studno 학번, tel 전화번호 from student
where tel like '02%'
----------------------------------------------------------------
select name, studno 학번, tel 전화번호 from student
where substr(tel,1,instr(tel,')',-1)) = '02'??
6. 학생 중 id에 'M'문자를 가지고 있는 학생의 이름, id, 학과번호1을 출력하기
select name,id, deptno1 학과번호1 from student
where id like lower('%M%')
-------------------------------------------------------------------------
select name,id, deptno1 학과번호1 from student
where lower(id) like '%M%'
7. 학생 테이블에서 학년이 2학년과 3학년이고, 학과가 101이거나 201인 학생의 학번, 이름, 학년, 학과1를 출력하기. 단 between 과 in 연산자를 사용하여 출력하기
elect studno 학번, name, grade 학년, deptno1 학과1 from student
where grade between 2 and 3 and deptno1 in (101,201)
---------------------------------------------------------------------
select studno 학번, name, grade 학년, deptno1 학과1 from student
where (grade = 2 and grade = 3) and (deptno1 = 101 deptno1 = 201)
8. EMP 테이블에서 급여가 1300에서 1700 사이인 사원의 성명, 업무(job), 급여(sal), 부서번호(deptno)를 출력하여라.
select ename 사원이름, job 업무, sal 급여, deptno 부서번호 from emp
where sal between 1300 and 1700
9. EMP테이블에서 사원번호(empno)가 7902, 7788, 7566 인 사원의 사원번호, 성명, 업무(job), 급여, 입사일자(hiredate)를 출력하여라.
select empno 사원번호, ename 성명, job 업무, sal 급여, hiredate 입사일자 from emp
where empno in ('7902','7788','7566')
10. EMP테이블에서 입사일자가 92년도에 입사한 사원의 사원번호, 성명, 담당업무, 급여, 입사일자, 부서번호를 출력하여라.
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호
from emp
where hiredate like '92%'
--------------------------------------------------------------------------------------
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호
from emp
where substr(hiredate,1,2) = '92'
11. EMP 테이블에서 이름의 첫 글자가 ‘M’인 사원의 이름, 급여를 조회하라.
select ename 이름, sal 급여 from emp
where ename like 'M%'
----------------------------------------------------
select ename 이름, sal 급여 from emp
where ename like substr(ename,1,1)
12. EMP 테이블에서 이름의 두 번째 글자가 ‘L’인 사원의 이름, 업무를 조회하라.
select ename 이름, sal 급여 from emp
where ename like 'M%'
-----------------------------------------------------
select ename 이름, sal 급여 from emp
where ename like substr(ename,1,1)
13. EMP 테이블에서 보너스(comm)가 NULL인 사원의 사원번호, 이름, 업무, 급여, 입사일자, 부서번호를 출력하여라.
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where comm is null
14. EMP 테이블에서 급여가 1100 이상이고, JOB이Manager인 사원의 사원번호, 성명, 담당업무, 급여, 입사일자, 부서번호를 출력하여라.
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where sal >= 1100 and job = 'MANAGER'
15. EMP 테이블에서 급여가 1100 이상이거나, 이름이 M으로 시작하지 않는 사원의 사원번호, 성명, 담당업무, 급여, 입사일자, 부서번호를 출력하여라.
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where sal >= 1100 and ename not like 'M%'
-------------------------------------------------------------------------------------------
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where sal >= 1100 and substr(ename,1,1) != 'M'--*****
16. EMP 테이블에서 JOB이 Manager, Clerk, Analyst가 아닌 사원의 사원번호, 성명, 업무, 급여, 부서번호를 출력하여라.
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where job not in (UPPER('Manager'), UPPER('Clerk'), UPPER('Analyst'))
-------------------------------------------------------------------------------------------
select empno 사원번호, ename 성명, job 담당업무, sal 급여, hiredate 입사일자, deptno 부서번호 from emp
where initcap(job) not in (('Manager'), ('Clerk'), ('Analyst'))
17. EMP 테이블에서 JOB이 PRESIDENT이고 급여가 1500 이상이거나 업무가 SALESMAN인 사원의 사원번호, 이름, 업무, 급여를 출력하여라
select empno 사원번호, ename 성명, job 담당업무, sal 급여 from emp
where (job = 'PRESIDENT' and sal >= 1500) OR (job = 'SALESMAN')
18. 교수 테이블에서 급여가 450 이상인 경우는 5%를 인상하고,
450 미만인 경우는 10%가 인상되도록 교수번호, 교수이름, 현재급여, 인상예정급여 을 출력하기.
인상예정 급여의 내림차순으로 정렬하기
select profno 교수번호, name 교수이름, pay 현재급여, pay*1.05 인상예정급여 from professor
where pay >= 450
union
select profno 교수번호, name 교수이름, pay 현재급여, pay*1.1 인상예정급여 from professor
where pay < 450
order by 인상예정급여 desc
19.학생 테이블에 1학년 학생의 이름과 주민번호기준생일, 키와 몸무게를 출력하기. 단 생일이 빠른 순서대로 정렬
select name, substr(jumin,1,6) 생일, height 키, weight 몸무게 from student
where grade in 1--in 말고 = 도 가능
order by substr(jumin,1,6)
20. 교수테이블(professor)급여가 300 이상이면서 보너스(bonus)을 받거나 급여가 450 이상인 교수 이름, 급여, 보너스을 출력하여라.
select name 교수이름, pay 급여, Bonus 보너스 from professor
where pay >= 300 and bonus is not null or pay >= 450
21. 201번 학과에 소속된 교수와 학생의 번호와 이름을 출력하여라.
select profno, name from professor
where deptno in 201
union all
select studno, name from student
where deptno1 in 201
22. 교수테이블에서 교수의 성이 ㅈ이 포함된 교수의 이름 출력하기 (between 연산자 사용)
select name from professor
where name between '자' and '찧'
23. EMP 테이블에서 부서번호(deptno)로 정렬한 후 부서번호가 같을 경우 급여(sal)가 많은 순으로 정렬하여 사원번호, 성명, 업무, 부서번호, 급여를 출력하기.
select empno 사원번호, ename 성명, job 업무, deptno 부서번호, sal 급여 from emp
order by deptno, sal desc
24. 1학년 학생중 몸무게가 60kg보다 작은 학생과 3학년 학생중 키가 170보다 큰 학생의 학번, 이름, 키,몸무게를 출력하라.
select studno 학번, name 이름, height 키, weight 몸무게, grade from student
where (grade = 1 and weight < 60) or (grade = 3 and height > 170)
----------------------------------------------------------------------------------
select studno 학번, name 이름, height 키, weight 몸무게, grade from student
where grade = 1 and weight < 60
union all
select studno 학번, name 이름, height 키, weight 몸무게, grade from student
where grade = 3 and height > 170
25. 교수테이블에서 교수번호, 교수이름, 학과코드, 급여, 보너스, 연봉을 출력하기 연봉은 보너스가 있는 경우 pay * 12 + bonus로 계산하고, 보너스가 없는 경우는 pay * 12로 계산하여 출력하기 단 학과코드로 정렬하고, 연봉이 큰순으로 정렬하기
select profno 교수번호, name 교수이름, deptno 학과코드, pay 급여, bonus 보너스, pay**12+bonus 연봉 from professor
where bonus is not null
union all
select profno 교수번호, name 교수이름, deptno 학과코드, pay 급여, bonus 보너스, pay**12 연봉 from professor
where bonus is null
order by 3, 6 desc
26. emp테이블에서 사원번호, 사원명, 급여를 출력하는데 부서코드(deptno)가 10인 부서 제외하여 출력하기
select empno 사원번호, ename 사원명, sal 급여, deptno from emp
where not deptno = 10
--------------------------------------------------------------------
select empno 사원번호, ename 사원명, sal 급여, deptno from emp
where deptno != 10--***
----------------------------------------------------------------------
select empno 사원번호, ename 사원명, sal 급여, deptno from emp
where deptno not in 10--***
27. 학생의 id의 길이가 7개이상 10개 이하인 학생의 학번, 이름, id, id의 글자수를 출력하기
select studno 학번, name 이름, id, length(id) "id의 글자수" from student
where length(id) between 7 and 10
28. 학생의 생년월일을 '98년 03월 20일' 의 형식으로, 이름과 생년월일을 월로 정렬하여 출력하기. 단 생년월일은 주민번호(jumin)을 기준으로 한다.
select name 이름, (substr(jumin,1,2)||'년 '||substr(jumin,3,2)||'월 '||substr(jumin,5,2)||'일') 생년월일 from student
order by substr(jumin,3,2) asc
29. EMP 테이블에서 scott의 사원번호, 성명, 담당업무(소문자로), 담당업무(대문자로), 첫 글자만 대문자로 변환하여 출력하여라.
select empno 사원번호,initcap(ename) 성명, lower(job) 담당업무, upper(job) 담당업무 from emp
where initcap(ename) = 'SCOTT'
30. EMP 테이블에서 이름의 첫 글자가 ‘K’보다 큰 사원의 사원번호, 이름, 업무(job)를 출력하여라.
select empno 사원번호, ename 이름,job 업무 from emp
where substr(ename,1,1) > 'K'
order by ename asc
--------------------------------------------------------------------
select empno 사원번호, ename 이름,job 업무 from emp
where upper(substr(ename,1,1)) > upper('K') --upper안써도 상관은 없음//함수위에 함수넣기가능
order by ename asc
31. EMP 테이블에서 이름이 6자리 이상인 사원의 이름과 업무를 출력하여라.
select ename 이름, job 업무, length(ename) from emp
where length(ename) >= 6
'수업 문제(국비 지원) > Oracle' 카테고리의 다른 글
| [ORACLE] 2022.08.19 - DML, DDL (0) | 2023.04.27 |
|---|---|
| [ORACLE] 2022.08.18 - join, Sub Query (0) | 2023.04.27 |
| [ORACLE] 2022.08.17 - 복수행 함수, 그룹함수 (0) | 2023.04.27 |
| [ORACLE] 2022.08.16 - 숫자, 날짜, 형 변환, 일반함수 (0) | 2023.04.27 |
| [ORACLE] 2022.08.11 - select구문 (0) | 2023.04.27 |