SQL 1484 Group Sold Products By The Date
2022/9/15 2:18:42
本文主要是介绍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
- 统计不同的数量,这里利用 \(count(distinct)\)
- 将多个字符串连接:\(group\_concat\)
- 注意是先 \(group\ by\) 然后再 \(order\ by\)
点击查看代码
# 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
这篇关于SQL 1484 Group Sold Products By The Date的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-26高性能表格工具VTable总体构成-icode9专业技术文章分享
- 2024-04-16软路由代理问题, tg 无法代理问题-icode9专业技术文章分享
- 2024-04-16程序猿用什么锅-icode9专业技术文章分享
- 2024-04-16自建 NAS 的方案-icode9专业技术文章分享
- 2024-04-14ansible 在远程主机上执行脚本,并传入参数-icode9专业技术文章分享
- 2024-04-14ansible 在远程主机上执行脚本,并传入参数, 加上remote_src: yes 配置-icode9专业技术文章分享
- 2024-04-14ansible 检测远程主机的8080端口,如果关闭,则echo 进程已关闭-icode9专业技术文章分享
- 2024-04-14result 成功怎么写-icode9专业技术文章分享
- 2024-04-14stopped 状态设置为变量,由外部传递进来-icode9专业技术文章分享
- 2024-04-14为什么ansible执行远程脚本需要放到后台-icode9专业技术文章分享