I have the following source table:
pid | code
----------
1 P2
2 P2
3 P3
4 P1
5 P2
6 P1
Now, I want to get the information how many times each code exists:
code | count
------------
P2 3
P1 2
P3 1
So I want to count the values from code column and assign it to the distinct set of available code values. Finally I want to order by count number.