Distinct Products Sold Per Day
MediumSQLDatabaseMathSorting
Description
Write a SQL query to return each sell_date with the number of distinct products sold that day, ordered by sell_date ascending. **Output columns (in order):** sell_date, num_sold
Table:
activities| Column | Type |
|---|---|
| sell_date | TEXT |
| product | TEXT |
Examples
Input:
CREATE TABLE activities (sell_date TEXT, product TEXT); INSERT INTO activities VALUES ('2020-01-01','A'),('2020-01-01','A'),('2020-01-01','B'),('2020-01-02','C');Output:
2020-01-01|2
2020-01-02|1Explanation:
Sales are grouped by day and the unique products in each day are counted, ordered by date.
Input:
CREATE TABLE activities (sell_date TEXT, product TEXT); INSERT INTO activities VALUES ('2021-05-05','X');Output:
2021-05-05|1Explanation:
Sales are grouped by day and the unique products in each day are counted, ordered by date.
Input:
CREATE TABLE activities (sell_date TEXT, product TEXT); INSERT INTO activities VALUES ('2020-02-02','A'),('2020-02-02','B'),('2020-02-02','C');Output:
2020-02-02|3Explanation:
Sales are grouped by day and the unique products in each day are counted, ordered by date.
Constraints
- •
Use standard SQL (SQLite).