表结构:
 
用户购买过的商品记录表product_buy主要列:
user_name  product_id
A        1
B        1
C        2
A        3
A        2
 
查询同时购买了product_id为 1,2,3的SQL语句:
SELECT user_name
FROM product_buy
WHERE product_id in(1,2,3)
GROUP BY user_name
HAVING COUNT(DISTINCT product_id) = 3;
要点:COUNT(DISTINCT ...)

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-06-16
  • 2022-12-23
  • 2021-05-27
  • 2021-12-14
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2021-11-25
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
相关资源
相似解决方案