전체 글90 [데이터베이스설계] 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. [데이터베이스설계] 3-8 set 멤버십 ( in / not in ) set 멤버십[in / not in]Set 멤버십 [where] => 값이 어떤 집합의 원소나 아니냐… [ in / not in ] - in = intersect- not in = except- where 부분 중 서브쿼리부분을 먼저 실행하고 그 자리를 대체하기 Q) find courses offered in Fall 2017 and in Spring 2018=> (select course_id from section where sem = ‘Fall’ and year = ‘2017’) intersect ( ~~ )=> select distinct course_id from section where semester = “Fall” and year = 2017 and .. 2024. 11. 27. [데이터베이스설계] 3-7 having절, 중첩 질의문 having절Having 절 + 조건 => group by가 있을 때, 그룹들 중 선택할 때 사용. 집계함수 많이 씀 - having 절에 집계함수 들어가는 일이 많다- group by가 있을 때, 그룹들 중 선택할 때 having 절을 사용- where 절은 그룹 형성 전에 실행되고, having 절은 그룹 구성 후에 적용됨- having 절은 select 전에 실행되어서, select에서 고르지 않은 컬럼을 조건으로 써도 됨 Q) find the names and average salaries of all departments whose average salary is greater than 42000=> select dept_name, avg(salary) as .. 2024. 11. 26. [데이터베이스설계] 3-6 집계함수, group by 집계함수집계함수 Aggregate Function => relation의 컬럼에 나타나는 값들에 대해 기능 수행 [모아서 계산]- avg = average value- min = minimum value- max = maximum value- sum = sum of values- count = number of values Q) find the average salary of instructors in the Computer Science department=> select avg(salary) //지금까지는 투플이 열거됐었음… from instructor where dept_name.. 2024. 11. 25. 이전 1 2 3 4 5 6 7 ··· 18 다음