I have a table with the following values (Please ignore index, here column with R1..R10 being the PK of the table.
1 R1 M1 Mo1
2 R2 M2 Mo3
3 R3 M4 Mo6
4 R4 M2 Mo1
5 R5 M7 Mo1
6 R6 M5 Mo2
7 R7 M6 Mo1
8 R8 M4 Mo4
9 R9 M9 Mo3
10 R10 M3 Mo9
I want to find a value of Mo[i] for which number of R[i] are max. For example in above case Mo1 has maximum number of R[i] values so it must return Mo1.
I have been doing the stuff using count, but not succeeded yet.
Here is what i wrote
select Mo from table1 where Mo=(select max(r.Mo),max(count((r.Mo))) from table1 )r group by r.Mo
Try this:
This first groups the table by the column
Mo, resulting inIt then orders this by the count which results in this:
And then it simply returns the first row of the result which results in
Mo1.