当前位置: 代码迷 >> Sql Server >> 求1SQL分析相同产品购买用户
  详细解决方案

求1SQL分析相同产品购买用户

热度:22   发布时间:2016-04-27 10:44:01.0
求一SQL分析相同产品购买用户
表结构如下
create table test
(userid int, --用户ID
 productid int --产品ID
)

需求,查询出购买相同5个以上产品的不同用户

------解决方案--------------------
SQL code
select userid,productid, count(1) from test group by userid,productid having count(1)>5
------解决方案--------------------
select userid,productid, count(1) from test group by userid,productid having count(1)>5
------解决方案--------------------
SQL code
;with TB as(   select userid,productid, (select count(1) from test a where a.userid =test.userid and a.productid=test.productid)as cs from test group by userid,productid)select * from TB where cs>5
  相关解决方案