I have a table which represents a "Contract" between two rows in another table. Given the data below, how can I get the most common Distributer for each EndUser?
Contracts
EndUserId | DistributerId | StartDate | EndDate
-----------------------------------------
1 | 8 | ... | ...
1 | 9 | ... | ...
1 | 9 | ... | ...
2 | 8 | ... | ...
2 | 8 | ... | ...
2 | 9 | ... | ...
3 | 8 | ... | ...
3 | 9 | ... | ...
The query I'm after must return the following:
EndUserId | DistributerId
-------------------------
1 | 9
2 | 8
3 | 8 or 9, it is of no consequence.
Thanks in advance! Searching hasn't been much help here because it's hard to describe the goal without sample data etc.