I have a MySQL table:
level box
1 1
2 2
3 2
1 3
2 1
2 3
2 3
3 1
How can I get this table with MySQL query?
box1 box2 box3
level1 1 0 1
level2 1 1 2
level3 1 1 0
I have a big table so request should be fast.
Thanks.
I believe this should do it, although there may be a more efficient method or one not requiring an aggregate.
Edit: Initially I misunderstood the requirement. Changed the
MAX()aggregate toCOUNT():Another method using
JOINs: