• vito4ico - Sunday, April 22, 2018 6:22 PM

    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?

    So. If you have ties you are looking to get both the records in your output yes?. Then using rank instead of row_number should work. No need for top 1 after using rank