Mysql
 sql >> Database >  >> RDS >> Mysql

SQL Group BY utilizzando stringhe in nuove colonne

Puoi partecipare agli events tabella su due query dai results tabella, una per ogni classe:

SELECT    event_data, class_40_winner, class_30_winner
FROM      events e
LEFT JOIN (SELECT result_event, name AS class_40_winner
           FROM   results 
           WHERE  class = 40 AND position = 1) c40 ON e.id = c40.result_event
LEFT JOIN (SELECT result_event, name AS class_30_winner
           FROM   results 
           WHERE  class = 30 AND position = 1) c30 ON e.id = c30.result_event