2015-10-04 56 views
1

我已经在系统中,这台所谓的系统跟踪的用户此表记录轨迹:我想科拉姆的查询次数,记录根据另外两个colums

我的表的examble:

user_id , event_id 
1  , 1 
1  , 1 
1  , 2 
2  , 2 
1  , 3 

我想查询计算每一个事件,但是,如果访问的用户数量访问事件超过一次,只算一次访问

我想这个结果

event_id , CountofVisitEvent 
1   , 1 
2   , 2 
3   , 1 

回答

2

使用COUNT(DISTINCT)

SELECT event_id, COUNT(DISTINCT user_id) AS CountofVisitEvent 
FROM systemtrack 
GROUP BY event_id