less than 1 minute read

Problem

problem-1484

Query

SELECT
    sell_date,
    COUNT(DISTINCT product) as num_sold,
    GROUP_CONCAT(DISTINCT product) as products
FROM
    Activities
GROUP BY
    sell_date
ORDER BY sell_date

Editorial Solution

Approach: Grouping and aggregation of strings

SELECT
    sell_date,
    COUNT(DISTINCT(product)) AS num_sold,
    GROUP_CONCAT(DISTINCT product ORDER BY product SEPARATOR ',') AS products
FROM
    Activities
GROUP BY
    sell_date
ORDER BY
    sell_date ASC

Tags:

Updated: