There is the table below: (columns: ID-CAUSE-WORK)
ID | CAUSE | WORK
A | C1 | W1
B | C1 | W1
C | C1 | W1
D | C1 | W1
E | C1 | W2
F | C1 | W2
G | C1 | W2
H | C1 | W3
I | C1 | W3
FF | C2 | W4
FG | C2 | W4
FG | C2 | W1
FG | C2 | W1
FG | C2 | W6
I want the two max values of work’s count per cause. That is, with a simple count(work) group by cause, the result would be:
cause | work| count(work)
c1 | w1 | 4
c1 | w2 | 3
c1 | w3 | 2
c2 | w4 | 2
c2 | w1 | 2
c2 | w6 | 1
I want to take only the 2 max counts works per cause:
c1 | w1 | 4
c1 | w2 | 3
c2 | w4 | 2
c2 | w1 | 2
This should work: