
Basically I have a table name myTable and inside has Name,Class , I would like to sort them out like the table below with a count of each name and number of 1,2,3s they have.Below is the codes I currently had but it work on small amount of entries, if the table has 20,000 lines it took a very long time to execute.
Select DISTINT(Name),
(Select count(*) from `myTable` d1 where d1.Name = dd.Name and Class=1),
(Select count(*) from `myTable` d2 where d2.Name = dd.Name and Class=2),
(Select count(*) from `myTable` d3 where d3.Name = dd.Name and Class=3)
from `myTable` dd
Order by Name;