开发者

A counting problem

开发者 https://www.devze.com 2023-03-08 08:42 出处:网络
I have a table with columns user_id, time_stamp and activity which I use for recoding user actions for an audit trail.

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

精彩评论

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