LoslegenKostenlos loslegen

Using CAST() and CONVERT()

In this lesson, you learned that your tables could store data with different types than you want. Sometimes you will need to convert these types to the correct ones to perform the operations you want.

The series table has a column named num_ratings that stores integer numbers, but this time it was designed as VARCHAR(5). You want to calculate the average of the num_ratings column, but you think that this column is an integer number.

You prepare the following query:

SELECT AVG(num_ratings)
FROM series
WHERE num_ratings BETWEEN 0 AND 5000

Diese Übung ist Teil des Kurses

Cleaning Data in SQL Server Databases

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

-- Use CAST() to convert the num_ratings column
SELECT AVG(___(num_ratings ___ ___))
FROM series
-- Use CAST() to convert the num_ratings column
WHERE ___(___ ___ ___) BETWEEN 0 AND 5000
Code bearbeiten und ausführen