Skip to content
Advertisement

GROUP BY Subquery returns more than one row

I’m looking for a way to solve the following situation. I have a table that I need to return only one number for each “p.pays“, This query is supposed to list “nom from table Pays” where at least half of the “athlete” have are in the table “Resultat” but my subquery returns more than one line is there a way I can match “p.code” in both the query and the subquery so it only returns 1 line per “p.code“.

Expected result, show Countries”Pays” where at least half of the athletes “Athlete” have won a medal (Athlete is in the Resultat table). :

Advertisement

Answer

You want to have two counts of athlethes in the country:

  • all athletes
  • the resultat athletes

Use a conditional count for this:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement