A hypothetical table contains the following coloumns:
id integer,
name char(6),
status integer
And has the following data:
id id2 type
--- ----- ----
01 Adam 1
02 Bob 1
03 Adam 2
04 Caymen 1
05 Ahmed 1
06 Basel 1
07 Ahmed 2
08 Bob 2
09 Ahmed 2
10 Mike 1
So it basically tracks status progression for different users.
I want to group on the count of statuses. In other words, I want to know how many users have only 1 status, how many have 2 statuses, how many have 3 statuses, etc.
The expected output would be something like this:
num_of_statuses count
--------------- -----
1 3
2 2
3 1
I tried with having, but cannot find a solution yet. Any syntax is OK. SQL/MySQL/DB2/Oracle.
If you don’t feel like using a nested query, you could avoid it like this: