Hi,
Gone through your requirement and the files attached by you. Please confirm if you just looking a query to get the desired output or others requirement also.
I can provide you the solution for this task , as I have good experience of working on database like SQL Server, Oracle and PostgreSQL. Hoping in requirement you need some query , procedure, view, function, trigger etc.
Looking for an opportunity to work for you.
Thanks