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 ระดับกลาง