본문 바로가기

데이터베이스설계33

[데이터베이스설계] 3-11 with 절 ( with 테이블명(컬럼명) as (투플 instance 정의) ) - 임시 relation을 만든다.with 절 - DB에 남지 않음, 해당 SFW 실행할때만 존재한다. 임시테이블 Q) find all departments with the maximum budget (= 단독 1위일수도 있고, 공동1위일수도 있음)=> with max_budget ( value ) as                 테이블명 = max_budget, 컬럼명 value. 컬럼1개            ( select max(budget)                        dept테이블의 budget의 최고값. 레코드도 1개임.              from department  )                         //학과이름은 모름. 최고값만 온다     select de.. 2025. 2. 15.
[데이터베이스설계] 3-10 from 절의 sub쿼리 from 절의 sub쿼리From 절 안의 SFW  - 원래 from절에는 테이블을 줘야하는데, 그 자리에 SFW의 임시테이블 줌… 어차피 테이블이긴 함  - 이 안에 집계함수를 주면, 그 변형된 테이블에서 뽑게 됨.   - 임시테이블 -> DB에 저장되지 않아서, 질의 처리 후 사라진다. Base 테이블과 다르다  - having 절을 쓸 필요가 없다   - 서브쿼리 안의 select에서 컬럼을 as로 개명해도 되고, 서브쿼리 밖에 as 테이블명(컬럼들 나열) Q)find average instructors’ salaries of those departments where average salary is greater than       $42,000                              .. 2025. 2. 15.
[데이터베이스설계] 3-9 exist existexist [ where ] => where exists 결과 = 서브쿼리가 비어있지 않으면 true를 리턴함    = result set에 투플이 1개라도 있으면 true임 where exists r => r이 공집합이 아니라면 true where not exists r => r이 공집합이라면 true Q) find all courses_id taught in both the Fall 2017 semester and in the Spring 2018 semester=> select course_id.   from section as S.   where semester = “Fall” and year = 2017 and          exists ( select * .              .. 2025. 2. 15.