Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

SQL Group BY usando strings em novas colunas


Você pode participar dos events tabela em duas consultas dos results tabela, um para cada 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