I have a table similar to:
user_id | action
1 a1
2 a1
1 a1
3 a1
2 a1
1 a2
2 a2
I have to find out the number of users who have done action a1, group by number of actions and number of users for a1.
eg in the above table, the output should be:
num_users num_action_a1
1 (user: 3) 1
2 (user: 1,2) 2
I tried following query
select user_id, count(user_id) from table where action = 'a1' group by user_id
Do I have to use nested group by ?