• george-178499

    Wow what a genius way to solve this. Was very impressed by your solution. It is helping me a lot. 
    Apologies for didn't posting the DDL & DML. 

    I had one edge case in which this solution didn't work for me. Two hospitals had the same total income in some month.

    I have tried to solve this by switching row_numbers to rank and adding top 1 with ties but this didn't work for me 🙁

    Is there any solution for this edge case?