If the data is in a database, then you do *NOT* want to solve it with C# code. You want and need to solve it with SQL code and SQL logic. (Which, incidentally, will be easier than solving it with C# code and logic.)
But in any case, we should not do your homework for you. How can you learn if you don't at least *TRY* to write the code yourself.
Write the code as far as you can. Whether in C# or SQL. Get at least *some* answers to start coming out, even if they aren't right. *THEN* show your code and ask for help again.