Hey there
From what i understand, you have a table that stores medals won by various contestants. Various contestants come from various coiuntries. You want to know how many medals in total each country has won.
The first thing i would do is generate a distinct list of those contestants who actually won a medal.
Secondly, i would then determine which countries each of these medal winning contestants belonged to.
Now that you know who has won a medal and what country they belong to, you can look back at the table of "medals won". Look at one country at a time. For each contestant who competes under that country, look at the "medals won" table. In that table, find the corresponding contestant and add the medals won to the total for the country. Repeat the process for each country.
I'm sure there is a more refined process to accomplish this task, but hopefully this will give you a starting point which can help you develop the logical process needed to accomplish this task.
good luck
Laura