开发者

A counting problem

I have a table with columns user_id, time_stamp and activity which I use for recoding user actions for an audit trail.

How can I COUNT th开发者_Go百科e number of unique user_id where time_stamp=0 when there might be multiple such rows, differing only in in the activity text?


Sounds like you need to use:

  SELECT COUNT(DISTINCT t.user_id)
    FROM YOUR_TABLE t
   WHERE t.time_stamp = 0
GROUP BY t.activity


select count(*) 
FROM (select t.user_id, count(*) actions
      FROM table t
      where t.time_stamp = 0
      group by t.user_id) u

Should do it for you (not the most straightforward way, but it shows how to do a couple of different things).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜