Sample Header Ad - 728x90

MySQL query to create a Matrix view using pivot

8 votes
1 answer
3964 views
I have a table with the following fields: p1 p2 s1 s2 where p1 -> player1, p2 -> player2, s1 -> game1, s2 -> game2 The number of players can vary from 3 - 10. The table have the results between them. For example let's suppose that we have 4 players: TIM, ROB, NICK, GEORGE and the matches between them: p1 p2 s1 s2 TIM ROB 4 0 NICK GEORGE 4 0 TIM NICK 0 4 ROB GEORGE 4 0 TIM GEORGE 4 0 ROB NICK 4 0 What I want to produce with the query is something like this: TIM ROB NICK GEORGE TIM X 4-0 0-4 4-0 ROB 0-4 X 4-0 4-0 NICK 0-4 4-0 X 4-0 GEORGE 0-4 0-4 0-4 X Is it possible somehow in MySQL? Thanks in advance.
Asked by dimoss (181 rep)
Oct 25, 2015, 06:45 AM
Last activity: Mar 10, 2025, 08:00 AM