NULL-Werte

SQL für Fortgeschrittene

Jasmin Ludolf

Data Science Content Developer, DataCamp

Fehlende Werte

  • COUNT(field_name) enthält nur nicht-fehlende Werte
  • COUNT(*) enthält fehlende Werte

 

null

  • Fehlende Werte
    • Menschliches Versagen
    • Information nicht verfügbar
    • Unbekannt
SQL für Fortgeschrittene

null

SELECT COUNT(*) AS count_records
FROM people;
|count_records|
|-------------|
|8397         |
SELECT *
FROM people;
|id|name              |birthdate |deathdate|
|--|------------------|----------|---------|
|1 |50 Cent           |1975-07-06|null     |
|2 |A. Michael Baldwin|1963-04-04|null     |
|3 |A. Raven Cruz     |null      |null     |
...
SQL für Fortgeschrittene

IS NULL

SELECT name
FROM people
WHERE birthdate IS NULL;
|name         |
|-------------|
|A. Raven Cruz|
|A.J. DeLucia |
|Aaron Hann   |
...
SQL für Fortgeschrittene

IS NOT NULL

SELECT COUNT(*) AS no_birthdates
FROM people
WHERE birthdate IS NULL;
|no_birthdates|
|-------------|
|2245         |
SELECT COUNT(name) AS count_birthdates
FROM people
WHERE birthdate IS NOT NULL;
|count_birthdates|
|----------------|
|6152            |
SQL für Fortgeschrittene

COUNT() vs IS NOT NULL

SELECT 
   COUNT(certification) 
   AS count_certification
FROM films;
|count_certification|
|-------------------|
|4666               |
SELECT 
   COUNT(certification) 
   AS count_certification
FROM films
WHERE certification IS NOT NULL;
|count_certification|
|-------------------|
|4666               |
SQL für Fortgeschrittene

NULL einfach ausgedrückt

  • NULL-Werte sind fehlende Werte
  • Sehr häufig
  • Verwende IS NULL oder IS NOT NULL, um:
    • Identifiziere fehlende Werte
    • Wähle fehlende Werte aus
    • Schließe fehlende Werte aus
SQL für Fortgeschrittene

Lass uns üben!

SQL für Fortgeschrittene

Preparing Video For Download...