I have a database of race results. Each race event has multiple classes.
events table:
event_id | event_date
---------+------------
1 | 11/5/14
2 | 11/12/14
3 | 11/19/14
results table:
result_event | name | class | position
-------------+---------------+-------+-----------
1 | Jason Smith | 40 | 1
1 | David Johnson | 40 | 2
1 | Randy White | 30 | 1
1 | Billy Hansen | 30 | 2
2 | Wally Mann | 40 | 1
2 | Shawn Little | 40 | 2
2 | Eric Davis | 30 | 1
2 | Tom Handy | 30 | 2
I want to create a summary table that lists the Event Date and the winners of each class.
Like this:
Event Date | Class 40 Winner | Class 30 Winner
------------+-----------------+------------------
11/5/14 | Jason Smith | Randy White
11/12/14 | Wally Mann | Eric Davis
What query would I need so that I can create a GROUP BY event_id and list winners in separate columns?
GROUP BYcannot help you here.