중급 SQL
Jasmin Ludolf
Data Science Content Developer, DataCamp


COUNT()SELECT COUNT(birthdate) AS count_birthdates
FROM people;
|count_birthdates|
|----------------|
|6152 |
SELECT COUNT(name) AS count_names, COUNT(birthdate) AS count_birthdates
FROM people;
|count_names|count_birthdates|
|-----------|----------------|
|6397 |6152 |
COUNT(field_name) 필드의 값을 셈COUNT(*) 테이블의 레코드 수를 셈*모든 필드를 의미SELECT COUNT(*) AS total_records
FROM people;
|total_records|
|-------------|
|8397 |
DISTINCT 중복을 제거하여 고유한 값만 반환SELECT language
FROM films;
|language |
|---------|
|Danish |
|Danish |
|Greek |
|Greek |
|Greek |
films 테이블에는 어떤 언어가 있을까?SELECT DISTINCT language
FROM films;
|language |
|---------|
|Danish |
|Greek |
COUNT()와 DISTINCT를 결합해 고유한 값의 개수를 계산SELECT COUNT(DISTINCT birthdate) AS count_distinct_birthdates
FROM people;
|count_distinct_birthdates|
|-------------------------|
|5398 |
COUNT()에는 중복 항목이 포함됨DISTINCT에는 중복 항목이 제외됨중급 SQL