-기말고사 성적이 95점 이상인 학번, 과목번호 과목명 , 성적
-- 조회하는 서브쿼리 하나 만들고
--학생테이블이랑 조인해서 학번, 학생이름, 과목번호, 과목명, 성적, 전공
--score, scgrade, student -> 하나의 서브쿼리
--course, professor -> 하나의 서브쿼리로 (당당교수가 없는 과목도 조회되도록)
--위 서브쿼리 테이블 2개를 다시 조인해서 결과
--기말고사의 성적을 조회할건데 담당교수가 없는 과목도 나올 수 있도록
--과목이름, 담당교수이름, 학생이름, 점수등급 함께 조회 과목번호 순서로 정렬
---화학과 교수중에 일반화학 수업을 하지 않는 교수들만 조회
--부서명이 erp인 정보를 조회
--부서명의 대, 소문자를 모를 때
select DNO
, lower(dname)
, upper(dname)
, initcap(dname)
from dept;
select*
from dept;
--부서명이 erp인 정보를 조회
--부서명의 대, 소문자를 모를 때
select dno, dname
from dept
where lower(dname) = 'erp';
--1-2, 문자 연산 함수
--concat
select concat(dno, ':', dname, ':' || loc)
from dept;
-- 두개 이상 안됨
select dno || ':' || dname || ':' || loc
from dept;
--- 섭스트
select substr(Orders, 1, 1)
from PROFESSOR;
--서브 오라클은 첫 번째 글자부터 몇개를 가져온다
select *
from professor
where substr(Orders, 1, 1) = '정';
-- 왜안되냐 또
select *
from PROFESSOR
where substr(orders, 2, 1) = '교';
select ename
, substr(ename, 2) --두번째 글자부터 모두
, substr(ename, -2)-- 뒤에서 두번째 글자부터 모두
, substr(ename, 1, 2) --첫번째 글짜부터 두글자
, substr(ename, -2, 2) --뒤에서 두번짹 글잦부터 두글자
from emp;
--length, lengthB
select Dname, length(dname), lengthb(dname)
from dept;
--현재 오라클이 사용중인 문자셋 AL32UTF8 -> 한글 3byte
select *
FROM NLS_DATABASE_PARAMETERS
where PARAMETER = 'NLS_CHARACTERSET'
or parameter = 'NLS_NCHAR_CHARACTERSET';
--듀얼테이블 : 오라클에서 제공해주는 가상의 기본 테이블 간단하게 날짜나 연산 또는 결과값을 보기 위해 사용
--원래 듀얼 테이블 수요자는 sys로 되어있는데 모든 User에서 접근 가능
select instr('DATABASE', 'A'),
instr('DATABASE', 'A', 3),
instr('DATABASE', 'A', 1, 3)
from dual;
select instr('DATABASE', 'A'), --첫번째 A의 위치
instr('DATABASE', 'A', 3), -- 세번째 글자인 T 다음의 첫번째 A의 위치
instr('DATABASE', 'A', 1, 3) -- 첫번째 글자 D 다음의 세번쨰 A의 위치
,
sysdate
,
1 + 2
from dual;
--트림
select trim('조' from '조병조'), --both 생략, 앞뒤의 조를 제거
trim(leading '조' from '조병조'), --앞에 있는 조 제거
trim(trailing '조' from '조병조'), --뒤에 있는 조 제거
trim(' 조 병 조 ') --공백 제거
from dual;
--lpad, rpad :charset 한글을 3byte로 잡아도 컴퓨터에서는 2byte로 사용하기 때문에 한글 연산자체는 2byte로 진행된다.
select lpad(ename, 10, '*'), --사원명 뒤에 *을 붙여서 총 길이를 10으로 만듬
rpad(ename, 10, '*') --사원명 앞에 *을 붙여서 총 길이를 10으로 만듬
from emp;
--직원이름을 출력하는데 마지막 글자만 제거해서 출력(substr, length)
select ename
, substr(ename, 2) --두번째 글자부터 모두
, substr(ename, -2)-- 뒤에서 두번째 글자부터 모두
, substr(ename, 1, 2) --첫번째 글짜부터 두글자
, substr(ename, -2, 2) --뒤에서 두번짹 글잦부터 두글자
from emp;
select Dname, length(dname), lengthb(dname)
from dept;
select ename, substr(ename, 1,length(ename)-1)
from emp;
select professor.* from PROFESSOR professor where professor.HIREDATE <
(select HIREDATE from professor where PNAME = '송강');
select emp.* from emp emp where emp.SAL > (select sal from emp where ENAME = '손하늘');
select student.* from student student where student.AVR = any (select avr from student where sname = '노육');
select student.sno, student.sname, course.cno, course.cname, score.result, student.major from STUDENT student, course course, score score where student.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95
;
select student.sno, student.sname, student.major from student student, (select b.sno, b.sname, course.cno, course.cname, score.result, b.major from STUDENT b, course course, score score where b.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95) A where student.sno = A.SNO ;
select professor.* from professor professor, course course where professor.PNO = course.PNO and course.Cname != '일반화학' and professor.section = '화학' ;
select student.* from student student where student.major in ('물리','화학') and student.AVR>=3;
select * from emp;
select * from DEPT
;
select emp.* from emp emp, dept dept where emp.DNO = dept.DNO and dept.DNAME = 'ERP';
select professor.* from PROFESSOR professor where professor.HIREDATE <
(select HIREDATE from professor where PNAME = '송강');
select emp.* from emp emp where emp.SAL > (select sal from emp where ENAME = '손하늘');
select student.* from student student where student.AVR = any (select avr from student where sname = '노육');
select student.sno, student.sname, course.cno, course.cname, score.result, student.major from STUDENT student, course course, score score where student.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95
;
select student.sno, student.sname, student.major from student student, (select b.sno, b.sname, course.cno, course.cname, score.result, b.major from STUDENT b, course course, score score where b.SNO = score.SNO and course.CNO = score.CNO and score.RESULT = 95) A where student.sno = A.SNO ;
select professor.* from professor professor, course course where professor.PNO = course.PNO and course.Cname != '일반화학' and professor.section = '화학' ;
select student.* from student student where student.major in ('물리','화학') and student.AVR>=3;
select * from emp;
select * from DEPT
;
select emp.* from emp emp, dept dept where emp.DNO = dept.DNO and dept.DNAME = 'ERP';
select * from dept;
select dno, lower(dname), upper(dname), initcap(dname) from dept;
select dno, upper(dname), lower(dname), initcap(dname) from dept;
select dno, dname from dept where lower(dname) = 'erp';
select concat(dno, ':',dname, ':'||loc) from dept;
select concat(dno|| ':'||dname,loc) from dept;
select dno || dname || loc || director from dept
;select * from professor;
select substr(Orders, 1,1) from professor;
select substr (orders,1,1) from PROFESSOR where substr(ORDERS,1,1) = '정';
select ename, substr(ename, 2) from EMP;
select * from dept;
select dname, length(dname), lengthb(dname) from dept;
select 1+2 from dual;
select trim('조' from '조병조') from dual;
select trim ('병' from '조병조') from dual;
SELECT REPLACE('조병조', '병', '') FROM dual;
select ename, substr(ename,2) from emp;
select ename, substr(ename,2)from emp;
[4월13일]중요한 수업내용 서브쿼리 차집합 교집합 합집합 (0) | 2023.04.13 |
---|---|
[오라클]4월 13일 문제와 문제풀이 (0) | 2023.04.13 |
[쿼리문제]4.12 (0) | 2023.04.12 |
[4월 12일 쿼리]수업내용 (0) | 2023.04.12 |
[sql intellij 연동문제] (0) | 2023.04.10 |
댓글 영역