【发布时间】:2020-10-05 15:03:00
【问题描述】:
我有一个物品清单(例如衬衫、上衣、裤子、阿迪达斯、耐克、彪马、口红、洗面奶等),我将它们分类为(衬衫、上衣、裤子 = 衣服、耐克、阿迪达斯、彪马 =鞋子,口红等=化妆)和像这样的格式的年份 2017-01-01。我想知道在同一日期有多少次购买两种类型的商品,例如,如果我在 2018-02-01 购买了化妆品和衣服,那么我想将“化妆品 + 衣服”这一类别计为 1,如果我在 2017 年 9 月 6 日购买了鞋子和化妆品,那么我想将其计为“鞋子 + 化妆品”类别的 1
我该怎么做?
我有一个名为 Items 的表格:
Year | Purchases |
------------------
2017-02-01 | makeup
2018-10-01 | shoes
2019-03-01 | makeup
2017-11-01 | shoes
2017-02-01 | clothing
2016-01-01 | shoes
2018-10-01 | clothing
2017-11-01 | clothing
2019-01-01 | makeup
2016-01-01 | makeup
想要的输出是这样的:
Year | Purchases | Count
-----------------------
2016 | Shoes + makeup | 1
2017 | Makeup +clothing | 1
2017 | shoes + Clothing | 2
2018 | Shoes + clothing | 1
...
【问题讨论】:
-
请在您的问题上标记数据库名称。 SQL 函数是高度特定于供应商的。
标签: sql group-by count aggregate-functions