I'm trying to create a query that takes values from different rows and put them into different columns. Here is the query I've come up with so far:
SELECT red.match_number AS 'Match #', red.redTeams AS 'Red Alliance', blue.blueTeams AS 'Blue Alliance', red.redScore AS 'Red Alliance Score', blue.blueScore AS 'Blue Alliance Score'
FROM(SELECT match_number, GROUP_CONCAT(team SEPARATOR ' | ') AS redTeams, score AS redScore
FROM `scout_data`
WHERE alliance_color = 'red'
GROUP BY match_number) AS red
LEFT JOIN (SELECT match_number, GROUP_CONCAT(team SEPARATOR ' | ') AS blueTeams, score AS blueScore
FROM `scout_data`
WHERE alliance_color = 'blue'
GROUP BY match_number) AS blue ON red.match_number = blue.match_number
Which creates a table like this:
But I want to separate the numbers in the blue and red alliance columns so it looks something like this:
Except without the qualifications column name. The structure of my table looks like this:
I've limited all the columns in the picture to just what's relevant to the query.