SQL Interview Questions – Group Sold Products By The Date

Spread the love

Problem Description –

Write an SQL query 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.

The query result format is in the following example.

Difficulty Level – Easy

Problem Link – Group Sold Products By The Date

Solution –

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

Rating: 1 out of 5.

Leave a Reply