Count Distinct Customers

EasySQLDatabaseMathSorting

Description

Write a SQL query to return the number of distinct customers in the orders table as a single value named cnt. **Output columns (in order):** cnt

Table:orders
ColumnType
idINT
customerTEXT

Examples

Input:CREATE TABLE orders (id INT, customer TEXT); INSERT INTO orders VALUES (1,'A'),(2,'B'),(3,'A');
Output:2
Explanation:

Counting the unique customer values gives how many different customers placed orders.

Input:CREATE TABLE orders (id INT, customer TEXT); INSERT INTO orders VALUES (1,'X');
Output:1
Explanation:

Counting the unique customer values gives how many different customers placed orders.

Input:CREATE TABLE orders (id INT, customer TEXT); INSERT INTO orders VALUES (1,'A'),(2,'A'),(3,'A');
Output:1
Explanation:

Counting the unique customer values gives how many different customers placed orders.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.