You can use ROW_NUMBER
ordering by COUNT
for this greatest n per group query.
WITH t
AS (SELECT yearmonth,
value,
min(team_id) AS team_id,
ROW_NUMBER() OVER (PARTITION BY yearmonth
ORDER BY COUNT(*) DESC) AS RN
FROM YourTable
GROUP BY yearmonth,
value)
SELECT yearmonth,
team_id
FROM T
WHERE RN = 1