diff --git a/README.md b/README.md index 5ab2bb0..8f328a2 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Have a good contributing! - [620. Not Boring Movies](./leetcode/easy/620.%20Not%20Boring%20Movies.sql) - [1068. Product Sales Analysis I](./leetcode/easy/1068.%20Product%20Sales%20Analysis%20I.sql) - [1407. Top Travellers](./leetcode/easy/1407.%20Top%20Travellers.sql) + - [1484. Group Sold Products By The Date](./leetcode/easy/1484.%20Group%20Sold%20Products%20By%20The%20Date.sql) 2. [Medium](./leetcode/medium/) - [176. Second Highest Salary](./leetcode/medium/176.%20Second%20Highest%20Salary.sql) - [184. Department Highest Salary](./leetcode/medium/184.%20Department%20Highest%20Salary.sql) diff --git a/leetcode/easy/1484. Group Sold Products By The Date.sql b/leetcode/easy/1484. Group Sold Products By The Date.sql new file mode 100644 index 0000000..8212ff0 --- /dev/null +++ b/leetcode/easy/1484. Group Sold Products By The Date.sql @@ -0,0 +1,30 @@ +/* +Question 1484. Group Sold Products By The Date +Link: https://leetcode.com/problems/group-sold-products-by-the-date/description/ + +Table Activities: + ++-------------+---------+ +| Column Name | Type | ++-------------+---------+ +| sell_date | date | +| product | varchar | ++-------------+---------+ +There is no primary key (column with unique values) for this table. It may contain duplicates. +Each row of this table contains the product name and the date it was sold in a market. + + +Write a solution to find for each date the number of different products sold and their names. + +The sold products names for each date should be sorted lexicographically. + +Return the result table ordered by sell_date. +*/ + +SELECT + sell_date, + COUNT(DISTINCT product) AS num_sold, + STRING_AGG(DISTINCT product, ',' ORDER BY product) AS products +FROM Activities +GROUP BY 1 +ORDER BY 1