...

/

Describing a Categorical Series

Describing a Categorical Series

Learn how to describe a categorical series using SQL.

Overview

Categorical values are taken from a limited set of known values. Common examples are user, product, category, and so on.

To demonstrate, we are going to use the following list of values:

Press + to interact
SELECT * FROM (VALUES ('orange'), ('apple'), ('banana'), ('apple')) AS t(fruit);

Counting distinct values

To count the number of rows, we can use the COUNT function as we did before:

Press + to interact
SELECT
COUNT(*)
FROM (
VALUES ('orange'), ('apple'), ('banana'), ('apple')
) AS t(fruit);

Using COUNT(*), we found that the series has 4 rows. However, our series can have duplicate values. If we want to know how many unique values we have in the series, we can use the DISTINCT ...