|
| 1 | +1484\. Group Sold Products By The Date |
| 2 | + |
| 3 | +Easy |
| 4 | + |
| 5 | +SQL Schema |
| 6 | + |
| 7 | +Table `Activities`: |
| 8 | + |
| 9 | + +-------------+---------+ |
| 10 | + | Column Name | Type | |
| 11 | + +-------------+---------+ |
| 12 | + | sell_date | date | |
| 13 | + | product | varchar | |
| 14 | + +-------------+---------+ |
| 15 | + There is no primary key for this table, it may contain duplicates. |
| 16 | + Each row of this table contains the product name and the date it was sold in a market. |
| 17 | + |
| 18 | +Write an SQL query to find for each date the number of different products sold and their names. |
| 19 | + |
| 20 | +The sold products names for each date should be sorted lexicographically. |
| 21 | + |
| 22 | +Return the result table ordered by `sell_date`. |
| 23 | + |
| 24 | +The query result format is in the following example. |
| 25 | + |
| 26 | +**Example 1:** |
| 27 | + |
| 28 | +**Input:** |
| 29 | + |
| 30 | + Activities table: |
| 31 | + +------------+------------+ |
| 32 | + | sell_date | product | |
| 33 | + +------------+------------+ |
| 34 | + | 2020-05-30 | Headphone | |
| 35 | + | 2020-06-01 | Pencil | |
| 36 | + | 2020-06-02 | Mask | |
| 37 | + | 2020-05-30 | Basketball | |
| 38 | + | 2020-06-01 | Bible | |
| 39 | + | 2020-06-02 | Mask | |
| 40 | + | 2020-05-30 | T-Shirt | |
| 41 | + +------------+------------+ |
| 42 | + |
| 43 | +**Output:** |
| 44 | + |
| 45 | + +------------+----------+------------------------------+ |
| 46 | + | sell_date | num_sold | products | |
| 47 | + +------------+----------+------------------------------+ |
| 48 | + | 2020-05-30 | 3 | Basketball,Headphone,T-shirt | |
| 49 | + | 2020-06-01 | 2 | Bible,Pencil | |
| 50 | + | 2020-06-02 | 1 | Mask | |
| 51 | + +------------+----------+------------------------------+ |
| 52 | + |
| 53 | +**Explanation:** |
| 54 | + |
| 55 | +For 2020-05-30, Sold items were (Headphone, Basketball, T-shirt), we sort them lexicographically and separate them by a comma. |
| 56 | + |
| 57 | +For 2020-06-01, Sold items were (Pencil, Bible), we sort them lexicographically and separate them by a comma. |
| 58 | + |
| 59 | +For 2020-06-02, the Sold item is (Mask), we just return it. |
0 commit comments