My tables:
tournaments
_______________________________________
| id | name | date |
|---------------------------|-----------|
| 12 | mytournament | 2016-01-01|
|---------------------------|-----------|
players
________________________
| idt | name | cat |
|-------------------|-----|
| 12 | john | A |
| 12 | bobby | A |
| 12 | anna | B |
| 12 | Fritz | B |
| 12 | george | C |
|-------------------|-----|
I would need a query that returns this:
id | name | date | nr of cat A | nr of cat B | nr of cat C
12 | mytournament | 2016-01-01 | 2 | 2 | 1
I am havint problems with the multiple count... Can't figure out how to join the query.
select t.id, t.name, t.date, count(p.cat) as countA from tournaments t join players p on (t.id = p.idt)
but I can not figure out how to specify it should only take the count where cat = A and how to add the additional counts for B and C.
any help appreciated. Thanks