Jump to content

Problem extracting top result grouping by year


Buchead

Recommended Posts

Hi,

 

I have a table for test results:

 

`results`

 

resultID

year

class

person

result

 

What I'm attempting to do is pull out the top person from each year for a given class. I can get it pull out 1 person per year, however it's not the top result. Tried using inner queries with different join but none work. Is what I'm attempting possible or should the query be cycled through with the year specified each time?

 

Many thanks.

Try (untested)

SELECT person FROM results AS r1 INNER JOIN
( SELECT MAX(result) AS result, year FROM results WHERE class = '<desiredClassValue>' GROUP BY year ) AS r2 USING( Result, year )
WHERE r1.class = '<desiredClassValue>'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.