NULL-waarden

Gevorderde SQL

Jasmin Ludolf

Data Science Content Developer, DataCamp

Ontbrekende waarden

  • COUNT(field_name) bevat alleen waarden die er zijn
  • COUNT(*) inclusief ontbrekende waarden

 

null

  • Ontbrekende waarden:
    • Menselijke fout
    • Informatie niet beschikbaar
    • Onbekend
Gevorderde SQL

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     |
...
Gevorderde SQL

IS NULL

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

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            |
Gevorderde SQL

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               |
Gevorderde SQL

NULL in het kort

  • NULL-waarden zijn ontbrekende waarden
  • Veelvoorkomend
  • Gebruik IS NULL of IS NOT NULL om:
    • ontbrekende waarden te identificeren
    • ontbrekende waarden te selecteren
    • ontbrekende waarden uit te sluiten
Gevorderde SQL

Laten we oefenen!

Gevorderde SQL

Preparing Video For Download...