ronscript
ronscript

Reputation: 407

How to query this is MySQL?

Matches

ID| radiant_name | dire_name | radiant_win
1 |          LV  |       LGD | true 
2 |         LGD  |        LV | false
3 |          LV  |       LGD | false
4 |          LV  |       LGD | false
5 |         LGD  |        LV | false

Desired OUTPUT :D :

ex.

Team "LV" wins 3.
Team "LGD" wins 2.

I Have tried:

Using Group by and SUM but the results is different.

ex. query:

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


ex. not desired results ~_~ :

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

Upvotes: 0

Views: 82

Answers (2)

user2009750
user2009750

Reputation: 3187

I believe this is what you are looking for, if wins per radiant team are needed:

SELECT radiant_team_id, count(*) FROM yourtable GROUP BY radiant_team_id HAVING radiant_win = 'true';

Or if you need wins per radiant teams, and wins per dire team too then you might wanna use UNIONS but i don't see why would you want that since you can find using above query.

Upvotes: 1

Sablefoste
Sablefoste

Reputation: 4192

Is this what you are looking for?

SELECT DISTINCT COUNT(radiant_team_id), radiant_team_id 
FROM yourtablename
WHERE radiant_win='true'

Upvotes: 1

Related Questions