数据库
首页 > 数据库> > SQL 1484 Group Sold Products By The Date

SQL 1484 Group Sold Products By The Date

作者:互联网

Table Activities:

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| sell_date   | date    |
| product     | varchar |
+-------------+---------+

There is no primary key 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 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.

Solution

点击查看代码
# Write your MySQL query statement below
select a.sell_date,
    count(distinct a.product) as num_sold,
    group_concat(
        distinct a.product order by a.product separator ','
    ) as products
from Activities a
group by a.sell_date
order by a.sell_date

标签:sell,product,Group,Sold,SQL,date,group,table,sold
来源: https://www.cnblogs.com/xinyu04/p/16691641.html