엔지니어가 되고 싶은 공돌이
11. Introduction to SQL (5) - Aggregate Functions 본문
11. Introduction to SQL (5) - Aggregate Functions
Geca 2019. 10. 17. 00:06
10. 1 concept
avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of values
10. 2 application
- Find the average salary of instructors in the Computer Science department
select avg (salary)
from instructor
where dept_name= ’Comp. Sci.’;
- Find the total number of instructors who teach a course in the Spring 2010 semester
select count (distinct ID)
from teaches
where semester = ’Spring’ and year = 2010
- Find the number of tuples in the course relation
select count (*)
from course;
10. 3 Group by
- Find the average salary of instructors in each department
select dept_name, avg (salary)
from instructor
group by dept_name;
: 따로따로 그룹을 만든다.
10. 4 Having
- Find the names and average salaries of all departments whose average salary is greater than 42000
select dept_name, avg (salary)
from instructor
group by dept_name
having avg (salary) > 42000;
:having은 그룹을 형성한 후에 적용되는 반면, where절은 그룹이 형성되기 전에 적용된다.
'Computer Science > Data Base' 카테고리의 다른 글
10. Introduction to SQL (4) - Set Operation (0) | 2019.10.16 |
---|---|
09. Introduction to SQL (3) - 부가적인 기본연산 (0) | 2019.10.16 |
08. Introduction to SQL (2) - Basic Query Structure (0) | 2019.10.16 |
07. Introduction to SQL (1) - Domain type & create, drop (0) | 2019.10.16 |
06. Intro to Relational Model(2) - Query Language (0) | 2019.10.16 |