Question:
- How to make merge or combine the 2 team results into 1? Or
- How to make it returns only in 1 row?
Table name: series_type
id| type| description
1 | 0| No series (Any team win 1 will be the winner)
2 | 1| Best of 3 (Any team wins 2 will be the winner else draw)
3 | 2| Best of 5 (Any team wins 3 will be the winner else draw)
Table name: teams
ID| name
1848158| LV
15| LGD
Table name: matches
ID| series_id | series_type | league_id | start_time |radiant_name | dire_name | radiant_win
1 | 8313 | 2 | 2096 | xxxxxxx1 | LV | LGD | true
2 | 8313 | 2 | 2096 | xxxxxxx2 | LGD | LV | false
3 | 8313 | 2 | 2096 | xxxxxxx3 | LV | LGD | false
4 | 8313 | 2 | 2096 | xxxxxxx4 | LV | LGD | false
5 | 8313 | 2 | 2096 | xxxxxxx5 | LGD | LV | false
Query:
SELECT series_id, team, SUM(Win) As Won, SUM(Loss) as Lost
FROM
( SELECT *,radiant_name as team,
CASE WHEN radiant_win = 1 THEN 1 ELSE 0 END as Win,
CASE WHEN radiant_win = 1 THEN 0 ELSE 1 END as Loss
FROM matches
UNION ALL
SELECT *,dire_name as team,
CASE WHEN radiant_win = 0 THEN 1 ELSE 0 END as Win,
CASE WHEN radiant_win = 0 THEN 0 ELSE 1 END as Loss
FROM matches
) as temp
WHERE series_id = 8313
GROUP By team
ORDER By Won, Lost DESC
Results: when group by series_id
series_id| team| Won| Lost|
8313| LV| 5| 5|
Results: when group by team
series_id| team| Won| Lost|
8313| LGD| 2| 3|
8313| LV| 3| 2|
Expected Results: i need it group by series_id
series_id| teamA| teamB| teamAWon| teamBWon| teamALost| teamBLost|
8313| LV| LGD| 3| 2| 2| 3|