mysql 根据相似商品的数量返回具有相似购买和 desc 订单的人
客户表
id | 名称 |
---|---|
1 | a |
2 | b |
3 | c |
4 | d |
采购表
Product_id | customer_id |
---|---|
x | 1 |
y | 1 |
x | 4 |
y | 4 |
x | 3 |
z | 2 |
客户表包含客户数据,采购表包含订单数据。 现在有个问题,我想要购买类似产品的客户 ID,并按类似商品的数量订购 例如: 如果我想要购买类似商品的客户,例如客户“a” 查询应返回
customer_id | 类似商品计数 |
---|---|
4 | 2 |
3 | 1 |
'a' 购买了 x,y d' 买了 x,y, c' 购买了 x,
所以 d 和 c 应该按相似项目计数 (desc) 返回订单,
我不擅长较大的 sql 查询,所以我需要问这个。
先感谢您
customers table
id | name |
---|---|
1 | a |
2 | b |
3 | c |
4 | d |
purchase table
product_id | customer_id |
---|---|
x | 1 |
y | 1 |
x | 4 |
y | 4 |
x | 3 |
z | 2 |
the customer table has customer data and purchase table has order data.
Now coming to question, I want customers id who bought similar products ordered by the count of similar items
eg:
if i want customers who bought similar items like customer 'a'
the query should return
customer_id | similar items count |
---|---|
4 | 2 |
3 | 1 |
'a' bought x,y
d' bought x,y,
c' bought x
so d and c should be returned order by similar items count (desc)
i am not good at larger sql queries, so i need to ask this.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将返回客户对以及为他们提供类似产品的数量。
will return customers pair and the amount of similar products for them.