BaşlayınÜcretsiz Başlayın

Imputing missing values (II)

What if you want to replace missing values in one column with another and want to check the replacement column to make sure it doesn't have any missing values? To do that you need to use the COALESCE statement.

SELECT Shape, City, COALESCE(Shape, City, 'Unknown') as NewShape
FROM Incidents
+----------------+-----------+-------------+
| Shape          |  City     |  NewShape   |
+----------------+-----------+-------------+
| NULL           | Orb       | Orb         |
| Triangle       | Toledo    | Triangle    |
| NULL           | NULL      | Unknown     | 
+----------------+-----------+-------------+

Bu egzersiz

Intermediate SQL Server

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

Replace missing values in Country with the first non-missing value from IncidentState or City, in that order. Name the new column Location.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

-- Replace missing values 
SELECT Country, ___(___, ___, ___) AS Location
FROM Incidents
WHERE Country IS NULL
Kodu Düzenle ve Çalıştır