selcet product_id, month from ( select product_id, month, row_number() over(partition by month order by amt desc) as rank from table ) t where rank = 1