How can I improve the efficiency of sorting this simple mysql? [Select distinct A. name from table A order by (select sum (num) as num from table where name = A. name) desc
In a table, the name field is repeated, and the num field is a number .. Show non-repeated names, and then sort the num with the same name plus the total number ..
The preceding SQL result is correct, which is very slow. More than 10 thousand records are slow because they are sorted ..
How can I quickly achieve this sort function after modification?
Reply to discussion (solution)
Select name, sum (num) as xxx from table group by name order by xxx desc
Statistics are not fast. adding a redundant statistical table is the right path.
Select name, sum (num) as xxx from table group by name order by xxx desc
Thank you. it is easy to use .. It is much faster than the original one ..