Notice
Recent Posts
Recent Comments
Link
05-22 13:02
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- java
- 마크다운 링크
- 취성패
- git push
- mysql한글깨짐
- Oracle join
- git오류
- jdbc연결테스트코드
- 마크다운 테이블
- SQL
- lombok.jar
- spring자바설정
- 한글깨짐
- Class<SpringJUnit4ClassRunner> cannot be resolved to a type
- @Setter(onMethod_ = @Autowired) Error
- ejected-non-fast-forward
- 마크다운 리스트
- 오라클
- git
- 오라클연습문제
- 정보처리기사
- 이클립스
- SpringJUnit4ClassRunner
- jdbc연결확인
- java.lang.NoClassDefFoundError:org/springframework/core/annotation/MergedAnnotations
- 마크다운 기본문법
- HTTP 상태 415 – 지원되지 않는 Media Type
- oracle
- rest방식
- 스프링
Archives
- Today
- Total
study-project
오라클 서브쿼리 사용법 (1) 본문
문법
select select_list
from table
where expr operator(select select_list from table);
기본적인 사용법은 이렇다
오라클은 서브쿼리를 먼저 실행하고 실행한 결과를 메인 쿼리로 넘기면서 실행되기 때문에
비교대상의 값을 직접 찾아오게 하거나 할 때 사용한다고 한다.
예시
select last_name,salary
from employees
where salary > (select salary from employees where lower(last_name)='abel');
employees 테이블에서 이름이 abel 인 사람의 salary 보다 많이 받는 사람들을 출력하는 문장이다.
이때 비교대상을 개발자가 직접 구해서 넣을수도 있지만 그것보다 오라클에서 찾아오게 하는것이 더 효율적이기
때문에 이렇게 사용한다
예시 2
select a.last_name,a.salary,a.department_id,b.salavg
from employees a join (select department_id,avg (salary)salavg
from employees group by department_id)b
on a.department_id = b.department_id
where a.salary >b.salavg;
a 인 employees 테이블에서 last_name과 salary, depamrtment_id,를
b.인 salavg를 이때 salavg는 employees 테이블에서 department_id 별로 그룹화해서 평균을 구한것을 말한다
그래서 부서별로 부서의 평균보다 많이 받는 사원들의 이름과 월급 아이디 평균월급을 출력하는 구문이다.
'DB > ORACLE' 카테고리의 다른 글
oracle savepoint 만들기 (0) | 2020.09.12 |
---|---|
inset,update 사용법 (commit, rollback) (0) | 2020.09.12 |
오라클 테이블 join (2) (0) | 2020.09.05 |
오라클 테이블 join (1) (0) | 2020.09.01 |
오라클 group by 절과 having 절 (0) | 2020.08.30 |
Comments