How to request a calculation of specific team victories and find a series winner

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: match

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

Result:
filter using league_id, start_time and radiant_name and dire_name
Example

Team "LV" total series wins 3.
Team "LGD" total series wins 2.
Series winner is LV.

Conclusion: I tried

Using a group by SERIES_ID and SUM, but the results are different.

example

SELECT SUM(IF(radiant_win = 1? 1, 0)) as LV, SUM(IF(radiant_win = 1? 0,1)) as LGD


ex. Unwanted results ~ _ ~

Team "LV" wins 1.
Team "LGD" wins 4.

Update (thanks to https://stackoverflow.com/users/3685967/bsting )
This query gives me the correct results, but theres 1 problem gives 2 columns. I need it in 1 line
select *, count(winner) as count from (select case radiant_win when 1 then radiant_name else dire_name end as winner, radiant_team_id, dire_team_id, series_id, series_type from matches   leagueid = 2096         start_time >= 1415938900        ((radiant_team_id = 1848158 dire_team_id = 15)           (radiant_team_id = 15 dire_team_id = 1848158))   ) temp ; >

Query Results Current Query

winner| radiant_team_id| dire_team_id| series_id| series_type| count|
   LGD|         1848158|           15|      8313|           2|     2
    LV|         1848158|           15|      8313|           2|     3

Query Results Desired Query

winner|loser|  radiant_name|   dire_name|   series_id| series_type| radiant_count| dire_count|
    LV|  LGD|           LV |         LGD|        8313|           2|             3|          2|
+4
1

,

select winner, count(winner) from 
   (select case radiant_win 
             when 1 then radiant_name 
             else dire_name 
           end as winner
     FROM test.`match` ) as temp
group by winner;
  • test.'match '- i, MySQL

start_time, radiant_team_id dire_team_id , , .

, , , , , .

select *, count(winner) as count 
from (select case radiant_win 
            when 1 then radiant_name 
            else dire_name 
        end as winner, 
        radiant_team_id, 
        dire_team_id,
        series_id,
        series_type
    from test.`matches` 
    where league_id = 2096 and 
          start_time >= 1415938900 and 
         ((radiant_team_id= 1848158 and dire_team_id= 15) 
           or (radiant_team_id= 15 and dire_team_id= 1848158)) 
    ) as temp
group by winner;
+4

All Articles