the question is difficult to summarize in the title, so here a more verbose example:

I have a huge dataset of dozens of measurements for thousands of different objects. Most of them have an associated type but this type is not unambiguous.

So a Select like 

```
SELECT oid, type, count(type) FROM data GROUP BY oid, type;

```

will produce something like:

```
oid   type  count(type)
 0      0   22
 1      0   22
 2      1   61
 2      2  104
 3      2   63
 4      0   34
 6      0    1
 8      2   76
 9      0    1
11      3   33
12      0   55
13      4    1
13      5   28
13      1    2
13      2  255
14      4  148
14      1    4
14      2    3
15      3   10
16      0   13
18      4  137
18      1    5

```

How can i get only one line per object to the result if this only line has to be the one with the most occurences? 

Bonus-Question: also get a percentage per object line that represents the occurrence ratio of this type.

The result should look like:

```
oid   type  P(type)
 0      0   1.0
 1      0   1.0
 2      2   0.64
 3      2   1.0
 4      0   1.0
 6      0   1.0
 8      2   1.0
 9      0   1.0
11      3   1.0
12      0   1.0
13      2   0.89
14      4   0.95
15      3   1.0
16      0   1.0
18      4   0.96

```

edit:

some test data and the almost-correct output of one solution:

<http://pastebin.com/jVvHErJ2>