I need to calculate the mode average by clinic. Test data as follows:
| Clinic | Test2 |
|---|---|
| A123 | 2 |
| A123 | 3 |
| A123 | 4 |
| A123 | 3 |
| A123 | 3 |
| B123 | 2 |
| B123 | 2 |
| B123 | 2 |
| B123 | 2 |
| B123 | 2 |
| B123 | 4 |
I can show the mode for all clinics using
SELECT TOP 1 test2, Clinic
FROM [JFF].[dbo].[Test_table]
GROUP BY clinic, test2
ORDER BY COUNT(*) DESC
However, I want the mode per clinic, not all clinics. What I really want is to show:
| Clinic | Mode |
|---|---|
| A123 | 3 |
| B123 | 2 |
Any help would be most appreciated. Thank you.