Reputation: 40140
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 the number of unique user_id where time_stamp=0 when there might be multiple such rows, differing only in in the activity text?
Upvotes: 0
Views: 68
Reputation: 13561
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).
Upvotes: 1
Reputation: 332561
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
Upvotes: 4